-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMusic3.java
More file actions
109 lines (82 loc) · 1.95 KB
/
Music3.java
File metadata and controls
109 lines (82 loc) · 1.95 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
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
105
106
107
108
109
package polymorphism;
import polymorphism.music.Note;
class Instrument {
public void play(Note n) {
System.out.println("Instrument.play() " + n);
}
public String what() {
return "Instrument";
}
public void adjust() {
System.out.println("Adjusting Instrument");
}
}
class Wind extends Instrument {
public void play(Note n) {
System.out.println("Wind.play() " + n);
}
public String what() {
return "Wind";
}
public void adjust() {
System.out.println("Adjusting Wind");
}
}
class Percussion extends Instrument {
public void play(Note n) {
System.out.println("Percussion.play() " + n);
}
public String what() {
return "Percussion";
}
public void adjust() {
System.out.println("Adjusting Percussion");
}
}
class Stringed extends Instrument {
public void play(Note n) {
System.out.println("Stringed.play() " + n);
}
public String what() {
return "Stringed";
}
public void adjust() {
System.out.println("Adjusting Stringed");
}
}
class Brass extends Wind {
public void play(Note n) {
System.out.println("Brass.play() " + n);
}
public void adjust() {
System.out.println("Adjusting Brass");
}
}
class Woodwind extends Wind {
public void play(Note n) {
System.out.println("Woodwind.play() " + n);
}
public String what() {
return "Woodwind";
}
}
public class Music3 {
public static void tune(Instrument i) {
i.play(Note.MIDDLE_C);
}
public 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);
}
}