-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusic4.java
More file actions
71 lines (66 loc) · 1.55 KB
/
Copy pathMusic4.java
File metadata and controls
71 lines (66 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.example.interfaces;
import com.example.*;
abstract class Instrument{
//
private int i;
public abstract void play(Note n);
public String what() { return "Instrument"+i; }
public abstract void adjust();
}
class Wind extends Instrument {
public void play(Note n) {
System.out.println("Wind.play() " + n);
}
public String what() { return "Wind"; }
public void adjust() {}
}
class Percussion extends Instrument {
public void play(Note n) {
System.out.println("Percussion.play() " + n);
}
public String what() { return "Percussion"; }
public void adjust() {}
}
class Stringed extends Instrument {
public void play(Note n) {
System.out.println("Stringed.play() " + n);
}
public String what() { return "Stringed"; }
public void adjust() {}
}
class Brass extends Wind {
public void play(Note n) {
System.out.println("Brass.play() " + n);
}
public void adjust() { System.out.println("Brass.adjust()"); }
}
class Woodwind extends Wind {
public void play(Note n) {
System.out.println("Woodwind.play() " + n);
}
public String what() { return "Woodwind"; }
}
public class Music4 {
static void tune(Instrument i) {
// ...
i.play(Note.C_SHARP);
}
static void tuneAll(Instrument[] e) {
for(Instrument i : e)
tune(i);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Instrument[] orchestra = {
new Wind(),
new Percussion(),
new Stringed(),
new Brass(),
new Woodwind()
};
tuneAll(orchestra);
}
}