2012-09-09 13:26:13 UTC
public static void main(String args[])
{
String fileName;
String morseA = ".-", morseB = "-...", morseC = "-.-.", morseD = "-..", morseE = ".",
morseF = "..-.", morseG = "--.", morseH = "....", morseI = "..", morseJ = ".---",
morseK = "-.-", morseL = ".-..", morseM = "--", morseN = "-.", morseO = "---",
morseP = ".--.", morseQ = "--.-", morseR = ".-.", morseS = "...", morseT = "-",
morseU = "..-", morseV = "...-", morseW = ".--", morseX = "-..-", morseZ = "--..",
morse1 = ".----", morse2 = "..---", morse3 = "...--", morse4 = "....-",
morse5 = ".....", morse6 = "-....", morse7 = "--...", morse8 = "---..",
morse9 = "----.", morse0 = "-----", morseCom = "--..--", morseQu = "..--..",
morsePeriod = ".-.-.-";
int choice = 0;
Scanner input = new Scanner(System.in);
System.out.println("Choose (1) to translate your english file to morse code or (2) morse code to english?");
choice = input.nextInt();
System.out.println("What is the name of the file? ");
fileName = input.next();
try
{
if (choice == 1)
{
Scanner fin = new Scanner(new File("C:\\" + fileName + ".txt"));
System.out.println(fileName +".txt is opened! Translation to morse code is in progress!" );
int c = 0;
while (fin.hasNext())
{
String txt = fin.nextLine();
System.out.print(txt);
if( txt.equals('H') || txt.equals('h') )
{
System.out.println(morseH);
}
}
} // end translation to morse code
else if (choice == 2)
{
Scanner fin = new Scanner(new File("C:\\" + fileName + ".mor"));
}
}
catch (Exception e)
{
System.out.println("Problems reading the file");
e.printStackTrace();
}
} // close main
} //end
Can someone tell me what i should add or change because i don't think i am doing it right?