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...
Please use Java language to write an efficient function that compute the intersection of two arrays...
Please use Java language to write an efficient function that compute the intersection of two arrays of integers (not necessary sorted).
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current...
PLEASE USE ARRAYS IN JAVA TO ANSWER THIS Write a 'main' method that examines its command-line...
PLEASE USE ARRAYS IN JAVA TO ANSWER THIS Write a 'main' method that examines its command-line arguments and calls the (add) method if the first parameter is a "+" calls the (subtract) method if the first parameter is a "-" calls the (doubled) method if the first parameter is a "&" add should add the 2 numbers and print out the result. subtract should subtract the 2 numbers and print out the results. Double should add the number to itself...
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...
Arrays Assignment in Java 1. Suppose you are doing a report on speeding. You have the...
Arrays Assignment in Java 1. Suppose you are doing a report on speeding. You have the data from 10 different people who were speeding and would like to find out some statistics on them. Write a program that will input the speed they were going. You may assume that the speed limit was 55. Your program should output the highest speed, the average speed, the number of people who were between 0-10 miles over, the number between 10 and 20,...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT