import java.util.Scanner;
import java.util.*;
import java.io.*;
public class Project1Array {
public static void main (String [] args)
{
int choice = 1;
Scanner morseorenglish = new Scanner(System.in);
System.out.println ("Choose either 1 or 2: (Type '1' for choice 1)");
System.out.println ("(1) Translate your English sentence into morse code");
System.out.println ("(2) Translate your morse code into an English sentence");
choice = morseorenglish.nextInt();
if (choice==1)
{
Scanner englishtomorse = new Scanner(System.in);
System.out.println ("Please enter an original sentence in English.");
String english = englishtomorse.nextLine();
System.out.println (englishtoMorse(english));
}
else
{
Scanner morsetoenglish = new Scanner(System.in);
System.out.println ("Please enter an original sentence in morse code.");
String morse = morsetoenglish.nextLine();
System.out.println (morsetoEnglish(morse));
}
}
public static String englishtoMorse(String english)
{
String[] alphabet = {"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", "7", "8", "9", "0"};
String a = ".- ";
String b = "-... ";
String c = "-.-. ";
String d = "-.. ";
String e = ". ";
String f = "..-. ";
String g = "--. ";
String h = ".... ";
String i = ".. ";
String j = ".--- ";
String k = "-.- ";
String l = ".-.. ";
String m = "-- ";
String n = "-. ";
String o = "--- ";
String p = ".--. ";
String q = "--.- ";
String r = ".-. ";
String s = "... ";
String t = "- ";
String u = "..- ";
String v = "...- ";
String w = ".-- ";
String x = "-..- ";
String y = "-.-- ";
String z = "--.. ";
String space = "| ";
String code[] = { 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 };
for(int variable = 0; variable < alphabet.length; ++variable)
{
if(english.equals(alphabet[variable]))
return code[variable];
}
return " ";
}
public static String morsetoEnglish(String morse)
{
String[] alphabet = {"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", "7", "8", "9", "0"};
String a = ".- ";
String b = "-... ";
String c = "-.-. ";
String d = "-.. ";
String e = ". ";
String f = "..-. ";
String g = "--. ";
String h = ".... ";
String i = ".. ";
String j = ".--- ";
String k = "-.- ";
String l = ".-.. ";
String m = "-- ";
String n = "-. ";
String o = "--- ";
String p = ".--. ";
String q = "--.- ";
String r = ".-. ";
String s = "... ";
String t = "- ";
String u = "..- ";
String v = "...- ";
String w = ".-- ";
String x = "-..- ";
String y = "-.-- ";
String z = "--.. ";
String space = "| ";
String code[] = { 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 };
for(int variable = 0; variable < code.length; ++variable)
{
if(morse.equals(code[variable]))
return alphabet[variable];
}
return " ";
}
}