Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Explanation / Answer

import java.util.Scanner; public class MorseCode { public static void main(String[] args){ /* 1.Set up assignments for morse and english characters 2. Accept input 3.Convert using methods... 4. Output */ Scanner choice = new Scanner(System.in); Scanner morseIn = new Scanner(System.in); Scanner engIn = new Scanner(System.in); System.out.print("Is the input string in morse code or in English? "); String Choice = choice.nextLine(); String Morse; String Eng; if (Choice.equals("morse")) { System.out.print("Enter a string in morse code: "); Morse = morseIn.nextLine(); methodMorse(Morse); } if (Choice.equals("English")) { System.out.print("Enter a string in English: "); Eng = engIn.nextLine(); StringBuffer output = methodEng(Eng); System.out.println("This string in morse code is: " + output); } } public static String methodMorse(String x){ //Convert using methods... String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " "}; String[] morse = {".- ","-... ","-.-. ","-.. ",". ","..-. ","--. ",".... ",".. ", ".--- ", "-.- ",".-.. ","-- ","-. ","--- ",".--. ","--.- ",".-. ","... ","- ","..- ", "...- ",".-- ","-..- ","-.-- ","--.. ", "| "}; String let; for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote