This project involves writing a program to translate Morse Code into English and English into Morse Code. Your program shall prompt the user to specify the desired type of translation, input a string of Morse Code characters or English characters, then display the translated results.
When inputting Morse Code, separate each letter/digit with a single space, and delimit multiple words with a “|”. For example, - --- | -… . would be the Morse Code input for the sentence “to be”. Your program only needs to handle a single sentence and can ignore punctuation symbols.
When inputting English, separate each word with a blank space.
I'm getting a incomparable types: String and char error in the if ( Morse [ m ] == b.charAt ( m ) ) line. Any ideas on how to fix this? Thanks!
public class project {
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 = { ".-" , "-..." , "-.-." , "-.." , "." , "..-." , "--." , "...." , ".." , ".---" , "-.-" , ".-.." , "--" , "-." , "---" , ".--." , "--.-" , ".-." , "..." , "-" , "..-" , "...-" , ".--" , "-..-" , "-.--" , "--.." , "|" };
String a = Input.getString ( "Please enter \"MC\" if you want to translate Morse Code into English, or \"Eng\" if you want to translate from English into Morse Code" );
if ( a == "MC" )
{
String b = Input.getString ( "Please enter a sentence in Morse Code. Separate each letter/digit with a single space and delimit multiple words with a | ." );
for ( int x = 0; x < Morse.length; x++ )
{
for ( int m = 0; m < b.length (); m++ )
{
if ( Morse [ m ] == b.charAt ( m ) )
System.out.print ( English [ m ] + " " );
}
}
}
else if ( a == "Eng" )
{
String c = Input.getString ( "Please enter a sentence in English, and separate each word with a blank space." );
c = c.toLowerCase ();
for ( int x = 0; x < English.length; x++ )
{
for ( int y = 0; y < c.length (); y++ )
{
if ( English [ x ] == c.charAt ( y ) )
System.out.print ( Morse [ x ] + " " );
}
}
}
else
{
System.out.println ( "Invalid Input" );
}
}
}