-
Notifications
You must be signed in to change notification settings - Fork 0
/
Music5.java
104 lines (86 loc) · 1.58 KB
/
Music5.java
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package Chapter9;
import static org.lozybean.util.Print.*;
enum Note{
MIDDLE_C, C_SHARP, B_FLAT;
}
interface Instrument{
int VALUE = 5;
void play(Note N);
void adjust();
}
class Wind implements Instrument{
public void play(Note n){
println(this + ".play() " + n);
}
public void adjust() {
println(this + ".adjust() ");
}
public String toString(){
return "Wind";
}
// it worked but not so clear
// public void another(){
//
// }
}
class Percussion implements Instrument{
public void play(Note N) {
println(this + ".play() " + N);
}
public void adjust() {
println(this + ".adjust()");
}
public String toString(){
return "Percussion";
}
}
class Stringed implements Instrument{
public void play(Note N) {
println(this + ".play() " + N);
}
public void adjust() {
println(this + ".adjust()");
}
public String toString(){
return "Stringed";
}
}
class Brass extends Wind{
public String toString(){
return "Brass";
}
}
class Woodwind extends Wind{
public String toString(){
return "Woodwind";
}
// public void another(){
// println(this + ".another()");
// }
}
public class Music5 {
static void tune(Instrument i){
i.play(Note.MIDDLE_C);
}
static void tuneAll(Instrument[] e){
for(Instrument i : e){
tune(i);
}
}
public static void main(String[] args){
Instrument[] orchestra = {
new Wind(),
new Percussion(),
new Stringed(),
new Brass(),
new Woodwind()
};
tuneAll(orchestra);
}
} /*output:
Wind.play() MIDDLE_C
Percussion.play() MIDDLE_C
Stringed.play() MIDDLE_C
Brass.play() MIDDLE_C
Woodwind.play() MIDDLE_C
*/