Question

In: Computer Science

answer in JAVA language please In this assignment you will use: one-dimensional arrays; strings and various...

answer in JAVA language please

In this assignment you will use: one-dimensional arrays; strings and various string-handling methods; file input and output; console input and output; loops; and conditional program statements.

Instruction

You are asked to write a program that translates a Morse code message into English language. The program will ask the user to enter filenames for two input files, one for the code translation table data and the other for the coded message data, as well as an output file that will receive the decoded message text. Initially the program reads the code translation table data file and stores the alphabet characters and equivalent Morse code in two one-dimensional arrays. The program will then read the message input file, inspecting each Morse code value and converting it to the English-language equivalent. The program will write decoded words to the output file and will print short informational messages to the console (screen).

Morse code words in the message input file have one space between each Morse-coded letter. There is ONE word per line in the data file.

Code Translation Table:

Character Code

  1. A .-

  2. B -...

  3. C -.-.

  4. D -..

  5. E .

  6. F ..-.

  7. G --.

  8. H ....

  9. I ..

  10. J .---

  11. K -.-

  12. L .-..

  13. M --

  14. N -.

  15. O ---

  16. P .--.

  17. Q --.-

  18. R .-.

  19. S ...

T-

Character Code U ..-
V ...- W .--

X -..- Y -.-- Z --.. 1 .--- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -..... 7 --... 8 ---.. 9 ----. 0 ----- , --..-- ? ..--.. . (full stop) .-.-.-

                                                                         

Assignment #3 Morse Code Translation

Test Plan

Given the input file CodedMessage.txt containing: - .... .. ...

.. ...

.-
- . ... -
.--. .-. --- --. .-. .- -- .-.-.- .. ..-.
-.-- --- ..-
... . .
- .... .. ...
-- . ... ... .- --. .
- .... .- -
.. ...
--. --- --- -..
-. . .-- ...
-.-- --- ..- .-.
.--. .-. --- --. .-. .- --
.-- --- .-. -.- ... .-.-.-

Here is a sample run. User input appears as bold underline:
Enter Morse Code translation table file path: c:/temp/morse.txt

Code translation file processed. 39 codes loaded.

Enter coded message input file path: c:/temp/CodedMessage.txt Enter decoded message output file path: c:/temp/DecodedMessage.txt Message translation complete. 17 words processed.

Here is the output file DecodedMessage.txt contents:

THIS IS A TEST PROGRAM.
IF YOU SEE THIS MESSAGE THAT IS GOOD NEWS YOUR PROGRAM WORKS.

answer in java language

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// codedMessage.txt (Input file)

.. ...
.-
- . ... -
.--. .-. --- --. .-. .- -- .-.-.- .. ..-.
-.-- --- ..-
... . .
- .... .. ...
-- . ... ... .- --. .
- .... .- -
.. ...
--. --- --- -..
-. . .-- ...
-.-- --- ..- .-.
.--. .-. --- --. .-. .- --
.-- --- .-. -.- ... .-.-.-

=====================================

// MorseCodeTranslator.java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class MorseCodeTranslator {

   public static void main(String[] args) throws IOException {
// Declaring variables
       String morseCode,text;
      
       // Opening the input file
       Scanner readFile = new Scanner(new File("CodedMessage.txt"));
       // Opening the output file
FileWriter fw=new FileWriter(new File("DecodedMessage.txt"));
  
// Reading the data from the input file
       while(readFile.hasNext())
       {
           morseCode=readFile.nextLine();
           // Calling the method
           text=getString(morseCode);
          
           // Writing to the output file
           fw.write(text+"\n");
       }
       readFile.close();
       fw.close();
   }
   // This will convert the morse code to normal text
   public static String getString(String morse) {
       String str = "";
       String args[] = morse.split(" ");
       for (int i = 0; i < args.length; i++) {
       str += morseToString(args[i]);
       }
       return str;
       }

   public static String morseToString(String morse) {
       String str = "";
       if (morse.equals(""))
       str = " ";
       else if (morse.equals("--..--"))
       str = ",";
       else if (morse.equals(".-.-.-"))
       str = ".";
       else if (morse.equals("..--.."))
       str = "?";
       else if (morse.equals("-----"))
       str = "0";
       else if (morse.equals(".----"))
       str = "1";
       else if (morse.equals(".----"))
       str = "2";
       else if (morse.equals("..---"))
       str = "3";
       else if (morse.equals("....-"))
       str = "4";
       else if (morse.equals("....."))
       str = "5";
       else if (morse.equals("-...."))
       str = "6";
       else if (morse.equals("--..."))
       str = "7";
       else if (morse.equals("---.."))
       str = "8";
       else if (morse.equals("----."))
       str = "9";
       else if (morse.equals(".-"))
       str = "A";
       else if (morse.equals("-..."))
       str = "B";
       else if (morse.equals("-.-."))
       str = "C";
       else if (morse.equals("-.."))
       str = "D";
       else if (morse.equals("."))
       str = "E";
       else if (morse.equals("..-."))
       str = "F";
       else if (morse.equals("--."))
       str = "G";
       else if (morse.equals("...."))
       str = "H";
       else if (morse.equals(".."))
       str = "I";
       else if (morse.equals(".---"))
       str = "J";
       else if (morse.equals("-.-"))
       str = "K";
       else if (morse.equals(".-.."))
       str = "L";
       else if (morse.equals("--"))
       str = "M";
       else if (morse.equals("-."))
       str = "N";
       else if (morse.equals("---"))
       str = "O";
       else if (morse.equals(".--."))
       str = "P";
       else if (morse.equals("--.-"))
       str = "Q";
       else if (morse.equals(".-."))
       str = "R";
       else if (morse.equals("..."))
       str = "S";
       else if (morse.equals("-"))
       str = "T";
       else if (morse.equals("..-"))
       str = "U";
       else if (morse.equals("...-"))
       str = "V";
       else if (morse.equals(".--"))
       str = "W";
       else if (morse.equals("-..-"))
       str = "X";
       else if (morse.equals("-.--"))
       str = "Y";
       else if (morse.equals("--.."))
       str = "Z";
       return str.toLowerCase();
       }

}

==========================================

decodedMessage.txt (Output file)

=====================Could you plz rate me well.Thank You


Related Solutions

java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following...
problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of -1 for all elements. Assume a value of -1 indicates an array element is empty. You are then to process the array, and remove duplicate elements from the array containing the numbers you...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You are NOT allowed to use any C++ string data type variable for any purpose. Moreover, you are allowed to add any include directive. You are not allowed to include string, cstdlib or math libraries. Also, you are not allowed to use any built-in functions of c-strings. can someone help with the third, fourth, and fifth functions? I tried many ways but i cannot figure...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You...
You are required to use C++ static or dynamic arrays of characters to store c-strings. You are NOT allowed to use any C++ string data type variable for any purpose. Moreover, you are allowed to add any include directive. You are not allowed to include string, cstdlib or math libraries. Also, you are not allowed to use any built-in functions of c-strings. can someone help with the third, fourth, and fifth functions? I tried many ways but i cannot figure...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
Please use markup language HTML5 please. For this homework assignment, you will create a Web site...
Please use markup language HTML5 please. For this homework assignment, you will create a Web site made up of three different pages and links between those pages Index.htm The Web pages in a site should have a similar look-and-feel. For this site, you should create a simple menu as follows: Create a horizontal line across the very top and bottom of the page. Also on the home (Index) page, create links to the other two pages. The links should appear...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep...
Please use java language in an easy way and comment as much as you can! Thanks...
Please use java language in an easy way and comment as much as you can! Thanks 1. A driver class with a main method, which creates instances of various objects (two of each subclass) and adds them as items to an ArrayList named "inventory". A foreach loop should loop through the ArrayList and call the use() method of each item. Define the ArrayList in a way that it only holds elements of the GameItem class and its subclasses. Make proper...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT