Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Morse Code Lab 1 ) Implement an interface Converter 2 ) Read in a file that express the code as pairs char to encode The

Morse Code Lab
1) Implement an interface Converter
2) Read in a file that express the code as pairs
char to encode
The combination of dashes and dots the represent it
3) Read in file to
Encode
Decode
Parameters:
Use two hashmaps
To store the strings for the letter and Morse code, use two hashmaps:
One to go from letter to morse
One to go from morse to letters
read the codes in from the MORSECODETABLE file
You should pass the filename into the object via the constructor (see main method)
Given Code:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args){
MorseConverter mc = new MorseConverter("MorseCodeTable.txt");
String workingDir = System.getProperty("user.dir")+"/";
mc.printKeyValuePairs();
String fileName = "Quote2.txt";
String copyfileName = "Quote2Copy.txt";
String saveFileName = "Quote2Morse.txt";
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(workingDir + fileName))){
String line ="";
while ((line = br.readLine())!= null){
sb.append(line);
}
}catch (FileNotFoundException e){
System.out.print(workingDir + fileName +" File Not found");
}
catch (IOException e){
e.printStackTrace();
}
mc.encodeSaveToFile(sb.toString(), workingDir + saveFileName);
String encodeCopy = mc.encode(sb.toString());
mc.decodeSaveToFile(encodeCopy, workingDir + copyfileName);
}
}
Given Interface:
public interface Converter {
public void printKeyValuePairs();
public String encode(String textToEncode);
public String decode(String textToDecode);
public boolean decodeSaveToFile(String decode, String filename );
public boolean encodeSaveToFile(String encode, String filename );
}
Given MorseCodeTable.txt
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 --..
0-----
1.----
2..---
3...--
4....-
5.....
6-....
7--...
8---..
9----.
..-.-.-
,--..--
?..--..
: ---...
'.----.

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

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions

Question

What is fraud examination?

Answered: 1 week ago

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago