Question: Can you please help me debug this code? Thank you! import java.util.Scanner; public class TranslateCode { final String[] alpha = {a, b, c, d, e,

Can you please help me debug this code? Thank you!

import java.util.Scanner;

public class TranslateCode {

final String[] alpha = {"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", " "};

final String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",

".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",

"...-" ,".--" ,"-..-", "-.--", "--..", "|"};

public static void main (String args []) {

Scanner input = new Scanner(System.in);

System.out.print("Type 1 for Morse to English translation. Input 2 for English to Morse translation: ");

int translate = input.nextInt();

for (int j = 0; j < 37; ++j)

{

System.out.print(toAlpha(String dot));

}

if (translate == 1)

{

Scanner Mor = new Scanner(System.in);

System.out.print("- -.-- .--. .|.. -.|.-|... . -. - . -. -.-. .");

String translate1 = scan.nextLine();

System.out.println(toEnglish(translate1));

}

if (translate == 2)

{

Scanner Eng= new Scanner(System.in);

System.out.print("Type in a sentence: ");

String translate2 = scan.nextLine();

System.out.println(toMorse(translate2));

}

public static String toEnglish(String translate1 )

{

final String[] alpha = {"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", " "};

final String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",

".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",

"...-" ,".--" ,"-..-", "-.--", "--..", "|"};

for (int i = 0; i

{

for(int i = 0; i < morse.length; ++i)

{

if(dot.equals(morse[i]))

return alpha[i];

}

return " ";

}

public static String toMorse(String translate2 )

{

final String[] alpha = {"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", " "};

final String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",

".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",

"...-" ,".--" ,"-..-", "-.--", "--..", "|"};

for (int i = 0; i

{

char [] chars = translate2.toCharArray();

if(translate2.equals(alpha[i]))

{

return morse[i];

}

}

return " ";

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!