Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read the question before you rush you answer , here is a screen shot of what the issue is going on when so when

Please read the question before you rush you answer , here is a screen shot of what the issue is going on when so when I type in english hi it spits out Morse Code which I want but when I enter the same Morse Code to translate to English it should repeat the word hi but it says "eeee"ee" trying to see what's going on .when I type the Morse Code it repeats different words need help the code and screen shot is 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.

image text in transcribed

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" };

// splitting it into array

String arr[] = message.split(" ");

String temp = "";

// iterating through the array

for (String s : arr) {

// getting index of morseCode

int i = getIndex(s);

// appening equalant char

temp = temp + chars[i];

}

// printing code

System.out.println(temp);

return (temp);

}

private static int getIndex(String aS) {

aS = aS + " ";

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

"-**-* ", "*---- ", "**--- ", "***-- ", "****- ", "***** ", "-**** ", "--*** ", "---** ", "----* ",

"----- ", "--** ", "-*-- ", "-**- ", "*--- ", "*--* ", "***- ", "*-- ", "**-* ", "**- ", "-*-* ",

"-*** ", "**** ", "*-** ", "*** ", "*-* ", "-** ", "--*- ", "-*- ", "--* ", "*- ", "-* ", "--- ", "** ",

"-- ", "- ", "* " };

int index = -1;

for (String s : mCodes) {

if (s.equalsIgnoreCase(aS))

return ++index;

index++;

}

return index;

}

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

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

}

for (int c = 0; c

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

}

System.out.println(Message);

return (Message);

}

public static void main(String[] args) {

System.out.println("Welcome to Translator:");

String ch="";

// added loop to ask input from user repeatedly

while(!ch.equals("-1")){

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

String msg;

Scanner sc = new Scanner(System.in);

msg = sc.nextLine();

// if -1 exit

if(msg.equals("-1"))

break;

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

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

ToEng(msg);

}

else {

ToMorse(msg);

}

System.out.println("Press any key to continue,-1 to exit");

ch=sc.next();

}

}

}

program [Java Application] /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java (Jar hi hi Press any key to continue,-1 to exit Please input your message: k-kx--k--ok-x-o-ok-x-kk-k---o-ktok

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Does IRR take into account the time value of money?

Answered: 1 week ago