MASM Write Morse Code Translator as per the following examp
MASM - Write Morse Code Translator as per the following example. User input in Orange, but you don\'t need to colorize your program - this is just for readability of this description. Remember to add comments about the app as mentioned in class (minimum 1 paragraph - full testing required).
Welcome to Morse Code Translator.
Please enter your name: Stephen Welcome, Stephen!
Would you like to... (1) Translate from Morse to ASCII (2) Translate from ASCII to Morse Enter (1/2): 1
Enter Morse Code: .-- .... .- - .----. ... / ..- .--. ..--..
ASCII Translation: WHAT\'S UP?
Would you like to make another translation (y/n)? y 1)
Translate from Morse to ASCII (2) Translate from ASCII to Morse Enter (1/2): 2
Enter ASCII text: How YOU doin\'?
Morse Code: .... --- .-- / -.-- --- ..- / -.. --- .. -. .----. ..--..
Would you like to make another translation (y/n)? n
Have a nice day, Stephen.
Solution
import java.util.Scanner;
public class MorseCodeProject1 {
public static void main(String[] args) {
char [] English = { \'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\', \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'0\' };
String [] Morse = { \".-\" , \"-...\" , \"-.-.\" , \"-..\" , \".\" , \"..-.\" , \"--.\" , \"....\" , \"..\" , \".---\" , \"-.-\" , \".-..\" , \"--\" , \"-.\" , \"---\" , \".--.\" , \"--.-\" , \".-.\" , \"...\" , \"-\" , \"..-\" , \"...-\" , \".--\" , \"-..-\" , \"-.--\" , \"--..\" , \"|\" };
Scanner input = new Scanner (System.in);
System.out.println( \"Please enter \\\"MC\\\" if you want to translate Morse Code into English, or \\\"Eng\\\" if you want to translate from English into Morse Code\" );
String a = input.nextLine();
if ( a.equalsIgnoreCase(\"MC\"))
{
System.out.println( \"Please enter a sentence in Morse Code. Separate each letter/digit with a single space and delimit multiple words with a | .\" );
String b = input.nextLine();
String[] words = null;
if(b.contains(\"|\")){
words = b.split(\"[|]\");
}
else{
words = new String[1];
words[0] = b;
}
for (String word: words )
{
String[] characters = word.split(\" \");
for(int h = 0;h < characters.length;h++){
for(int i = 0;i < Morse.length;i++){
if(characters[h].equals(Morse[i])){
System.out.print(English[i]);
}
}
}
System.out.print(\" \");
}
}
else if ( a.contains(\"Eng\" ))
{
System.out.println(\"Please enter a sentence in English, and separate each word with a blank space.\");
String c = input.nextLine();
c = c.toLowerCase ();
for ( int x = 0; x < c.length(); x++ )
{
for ( int y = 0; y < English.length; y++ )
{
if ( English [ y ] == c.charAt ( x ) )
System.out.print ( Morse [ y ] + \" \" );
}
}
}
else
{
System.out.println ( \"Invalid Input\" );
}
}


