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

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!