added ex P
This commit is contained in:
parent
1255f304fc
commit
bc4dfb6ef0
13
src/exercises/ex_p/Drum.java
Normal file
13
src/exercises/ex_p/Drum.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package exercises.ex_p;
|
||||||
|
|
||||||
|
public class Drum {
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public Drum(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play() {
|
||||||
|
System.out.println("Playing " + name);
|
||||||
|
}
|
||||||
|
}
|
38
src/exercises/ex_p/Partition.java
Normal file
38
src/exercises/ex_p/Partition.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package exercises.ex_p;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class Partition {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Drum bassDrum = new Drum("Bass Drum");
|
||||||
|
Drum floortom = new Drum("Floor Tom");
|
||||||
|
Drum snareDrum = new Drum("Snare Drum");
|
||||||
|
Drum rackTom = new Drum("Rack Tom");
|
||||||
|
Drum hiHat = new Drum("Hi-Hat");
|
||||||
|
Drum crashCymbal = new Drum("Crash Cymbal");
|
||||||
|
Drum rideCymbal = new Drum("Ride Cymbal");
|
||||||
|
Drum splashCymbal = new Drum("Splash Cymbal");
|
||||||
|
Drum chinaCymbal = new Drum("China Cymbal");
|
||||||
|
ScheduledExecutorService executor = Executors.newScheduledThreadPool(9);
|
||||||
|
int initialDelay = 1000;
|
||||||
|
int quaver = 500; // croche
|
||||||
|
int crotchet = 1000; // noire
|
||||||
|
int minim = 2000; // blanche
|
||||||
|
TimeUnit unit = TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
|
Drum[] drums = {
|
||||||
|
bassDrum, floortom, snareDrum,
|
||||||
|
rackTom, hiHat, crashCymbal,
|
||||||
|
rideCymbal, splashCymbal, chinaCymbal
|
||||||
|
};
|
||||||
|
int[] notes = {quaver, crotchet, minim};
|
||||||
|
|
||||||
|
for (int i=0; i < 9; i++) {
|
||||||
|
Drum drum = drums[i];
|
||||||
|
int rhythm = notes[(int) (Math.random() * 3)];
|
||||||
|
executor.scheduleAtFixedRate(drum::play, initialDelay, rhythm, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user