- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice.java
More file actions
Latest commit
42 lines (37 loc) · 1.59 KB
/
Copy pathPractice.java
File metadata and controls
42 lines (37 loc) · 1.59 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
importjava.io.File;
importjava.io.IOException;
importjavax.sound.sampled.*;
importjava.lang.Math;
importjava.util.concurrent.TimeUnit;
publicclassPractice {
publicstaticvoidmain(String[] args) throwsLineUnavailableException, UnsupportedAudioFileException, IOException, InterruptedException {
Stringdirectory = System.getProperty("user.dir") + "\\MorseCodeSounds\\";
Stringmorse[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-",
".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
"-.--", "--.."};
for(inti = 0; i<26; ++i) {
newSound(newFile(directory + Character.toString((char) ('a' + i)) + ".wav"), morse[i], Character.toString((char) ('a' + i)));
}
newSound(newFile(directory + "correct.wav"), "", "correct");
newSound(newFile(directory + "incorrect.wav"), "", "incorrect");
while(true) {
Soundcurrent = Sound.getSound(((int) (Math.random()*26)));
System.out.println("What letter is this?" + " " + current.getMorse());
Stringin = null;
do {
current.playSound();
in = System.console().readLine();
} while(in.equals("repeat"));
if(in.equals("exit")) {
break;
} elseif(in.equals(current.getName())) {
System.out.println("Correct");
Sound.getSound("correct").playSound();
} else {
System.out.println("Incorrect. The correct letter was " + current.getName() + ".");
Sound.getSound("incorrect").playSound();
}
TimeUnit.MILLISECONDS.sleep(100);
}
}
}