public class Project1
{
static String E [] = { "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", " " };
static String M [] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----", "|" };
public String input[];
public String output[];
static String TranslationType;
static boolean Bool;
static String TextToTranslate;
static int i;
static int SectionOfString;
static StringBuffer emcStringBuffer = new StringBuffer();
static StringBuffer mceStringBuffer = new StringBuffer();
static String emc = "English-MorseCode";
static String mce = "MorseCode-English";
static StringBuffer MorseCodeLetter = new StringBuffer();
static String emcString;
static String mceString;
static String space = " ";
public static void main( String [] args )
{
if ( E.length != M.length )
{
System.out.println( "Error" );
}
TranslationType = Input.getString( "Please choose a method of translation (\"English-MorseCode\" or \"MorseCode-English\") " );
if ( TranslationType.equals( "English-MorseCode" ) )
{
Bool = true;
System.out.println( TranslationType );
}
else if( TranslationType.equals( "MorseCode-English" ) )
{
Bool = false;
System.out.println( TranslationType );
}
while ( !TranslationType.equals( emc ) && !TranslationType.equals( mce ) )
{
System.out.println( "Error: \"" + TranslationType + "\" is not a valid response.");
TranslationType = Input.getString( "Please choose a method of translation (\"English-MorseCode\" or \"MorseCode-English\") " );
if ( TranslationType.equals( "English-MorseCode" ) )
{
Bool = true;
System.out.println( TranslationType );
}
else if( TranslationType.equals( "MorseCode-English" ) )
{
Bool = false;
System.out.println( TranslationType );
}
}
TextToTranslate = Input.getString( "What would you like to translate?" );
TextToTranslate = TextToTranslate.toUpperCase();
System.out.println( TextToTranslate );
if ( Bool == true )
{
for ( SectionOfString = 0; SectionOfString < TextToTranslate.length(); SectionOfString++ )
{
for ( i = 0; i < E.length; i++ )
{
if ( TextToTranslate.substring( SectionOfString, SectionOfString + 1 ).equals( E[i] ) )
{
emcStringBuffer.append( M[i] + " " );
}
}
}
emcString = emcStringBuffer.toString();
System.out.println( emcString );
}
else if ( Bool == false )
{
for ( SectionOfString = 0; SectionOfString < TextToTranslate.length(); SectionOfString++ )
{
if ( TextToTranslate.substring( SectionOfString, SectionOfString + 1 ).equals( space ) )
{
for ( i = 0; i < M.length; i++ )
{
if ( MorseCodeLetter.toString().equals( M[i] ) )
{
mceStringBuffer.append( E[i] );
}
}
}
else
{
if ( TextToTranslate.substring( SectionOfString, SectionOfString + 1 ).equals( M[36] ) )
{
mceStringBuffer.append( E[36] );
}
else
{
MorseCodeLetter.append( TextToTranslate.substring( SectionOfString, SectionOfString + 1 ) );
}
}
}
mceString = mceStringBuffer.toString();
System.out.println( mceString );
}
System.out.println( "Done" );
}
}