This program will convert English to Morse Code. It will use JOptionPane. The pr
ID: 3536162 • Letter: T
Question
This program will convert English to Morse Code. It will use JOptionPane. The program will loop until QUIT is requested. eee is the command to Quit.
Create separate files for each of the classes described in the attached UML Class diagram.
Following is the Object Oriented design to 'send' the Morse Code. Create the Elements exactly as specified in this design and it will work.
http://en.wikipedia.org/wiki/Morse_code
International Morse code is composed of five elements:
The unit length in Element is based on the following: "PARIS or CODEX are frequently used as a Morse code standard word. Using the word PARIS as a standard, the number of dot units is 50 and a simple calculation shows that the dot length at 20 words per minute is 60 milliseconds. Using the word CODEX with 60 dot units, the dot length at 20 words per minute is 50 milliseconds."
One simplification is to include an inter-element gap after the dit and the dah. However, the last dit or dah in a Morse character will have this extra gap which must then be compensated for in the gap between letters and words.
Note that the play() method in the subclasses is a public class method() (static). This being the case, the base class getters and setters are not accessible because they are NOT class methods. Either of two things:
Here is the Tone code:
import java.util.*;
import javax.sound.sampled.*;
public class Tone {
public static float SAMPLE_RATE = 8000f;
public static void sound(int hz, int msecs, double vol)
{
byte[] buf = new byte[(int)SAMPLE_RATE * msecs / 1000];
for (int i=0; i<buf.length; i++) {
double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI;
buf[i] = (byte)(Math.sin(angle) * 127.0 * vol);
}
// shape the front and back 10ms of the wave form
for (int i=0; i < SAMPLE_RATE / 100.0 && i < buf.length / 2; i++) {
buf[i] = (byte)(buf[i] * i / (SAMPLE_RATE / 100.0));
buf[buf.length-1-i] =
(byte)(buf[buf.length-1-i] * i / (SAMPLE_RATE / 100.0));
}
AudioFormat af = new AudioFormat(SAMPLE_RATE,8,1,true,false);
try
{
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
sdl.write(buf,0,buf.length);
sdl.drain();
sdl.close();
}
catch (LineUnavailableException e) {
System.out.println(e.getMessage());
}
} // end Sound
} // end Tone
Thanks in advance for any help.