Question: 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

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.

This is what I have so far :

main.java:

package me

import java.util.Scanner;

/** * */ public class Main {

/** * @param args the command line arguments */ public static void main(String[] args) { System.out.printf("Welcome to translator! "); Scanner scanner = new Scanner(System.in); while (true) { System.out.printf("Enter text to translate (-1 to exit): "); String translateMe = scanner.nextLine();

if ("-1".equals(translateMe)) { break; } Translator translator = TranslatorFactory.getInstance(translateMe);

if (translator == null) { System.out.printf("%nUnable to determine the language%n%n"); } else { System.out.printf("%nDetected language: %s%n%n", translator.getLanguage()); System.out.printf("%s%n%n", translator.translate(translateMe)); } } System.out.printf(" Good bye! "); } }

package me

import java.util.ArrayList; import java.util.Arrays;

/** * */ public class Primer { private static ArrayList lettersAndNumbers = new ArrayList<>(Arrays.asList(new String[]{"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"})); private static ArrayList morse = new ArrayList<>(Arrays.asList(new String[]{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----"})); public Primer() {} public boolean isEnglish(char c) { return lettersAndNumbers.contains(String.valueOf(c)); } public boolean isMorse(char c) { return morse.contains(String.valueOf(c)); } public String toEnglish(String dotsAndDashes) { int idx = morse.indexOf(dotsAndDashes); return (idx == -1) ? null : lettersAndNumbers.get(idx); } public String toMorse(String letterOrNumber) { int idx = lettersAndNumbers.indexOf(letterOrNumber); return (idx == -1) ? null : morse.get(idx); } }

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!