Question: ok So I have everything working except when the user enters morse it does not input English . need help with this one thing I

ok So I have everything working except when the user enters morse it does not input English . need help with this one thing I have the code below :

In a java program Need to find the purpose of this application have to create an application which is able to translate between back and forth between English letters A-Z and numbers 0-9 and Morse code dots . and dashes -. The user will be prompted to enter something to translate. The user may enter either English or Morse code. The application will then analyze what the user entered to try and figure out if the user entered English or Morse code. If the analysis determines the user entered something in English, it will then translate it into Morse code. If the analysis determines the user entered something in Morse code, it will then translate it into English. At any time, the user may enter -1 to exit the application.

HINT: Morse code is only dots . Dashes - and spaces . If the user input contains these 3 characters and only these 3 characters, its Morse code. Otherwise, assume its English.

Code :

import java.util.Scanner;

public class program

{

public static String ToEng(String message){

String[] mCodes={"*-*-*- ", "*-**-* ", "--**-- ", "**--** ","-*--*- ", "-*--*-", "*----* ", "-*-*-- ", "-**-* ", "*---- ", "**--- ", "***-- ", "****- ", "***** ", "-**** ", "--*** ", "---** ", "----* ", "----- ", "--** ", "-*-- ", "-**- ", "*--- ", "*--* ", "***- ", "*-- ", "**-* ", "**- ", "-*-* ", "-*** ", "**** ", "*-** ", "*** ", "*-* ", "-** ", "--*- ", "-*- ", "--* ", "*- ", "-* ", "--- ", "** ", "-- ", "- ", "* "};

String[] chars={".", "\"", ",", "?", "(", ")", "'", "!", "/", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "z", "y", "x", "j", "p", "v", "w", "f", "u", "c", "b", "h", "l", "s", "r", "d", "q", "k", "g", "a", "n", "o", "i", "m", "t", "e"};

for(int a=0; a<=44; a++){

message=message.replace(mCodes[a], chars[a]);

}

System.out.println(message);

return(message);

}

public static String ToMorse(String Message){

String[] mcodes={"*- ", "-*** ", "-*-* ", "-** ", "* ", "**-* ", "--* ", "**** ", "** ", "*--- ", "-*- ", "*-** ", "-- ", "-* ", "--- ", "*--* ", "--*- ", "*-* ", "*** ", "- ", "**- ", "***- ", "*-- ", "-**- ", "-*-- ", "--** ", /*numbers*/ "*---- ", "**--- ", "***-- ", "****- ", "***** ", "-**** ", "--*** ", "---** ", "----* ", "----- ", /*Stop*/ "*-*-*- ", /*quotation marks*/ "*-**-* ", /*comma*/ "--**-- ", /*question mark*/ "**--** ", /*parentheses*/"-*--*- ", "-*--*-", /*apostrophe*/ "*----* ", /*exclamation mark*/ "-*-*-- ", /*slash*/ "-**-* "};

String[] Chars={"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[] caps={"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 b=0; b<=44; b++){

Message=Message.replace(Chars[b], mcodes[b]);

}

for (int c=0; c<=25; c++){

Message=Message.replace(caps[c], mcodes[c]);

}

System.out.println(Message);

return(Message);

}

public static void main(String[] args) {

System.out.println("Please input your message:");

String msg;

Scanner sc=new Scanner(System.in);

msg=sc.nextLine();

System.out.println(msg+" ");

if (msg.contains("*")){

ToEng(msg);

}

else{

ToMorse(msg);

}

}

}

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!