In: Computer Science
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
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
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
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