Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Understand the primary objectives of performance appraisals

Answered: 1 week ago