Answered step by step
Verified Expert Solution
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
Implement an interface Converter
Read in a file that express the code as pairs
char to encode
The combination of dashes and dots the represent it
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.ioBufferedReader;
import java.ioFileNotFoundException;
import java.ioFileReader;
import java.ioIOException;
public class Main
public static void mainString args
MorseConverter mc new MorseConverterMorseCodeTabletxt;
String workingDir System.getPropertyuserdir";
mcprintKeyValuePairs;
String fileName "Quotetxt;
String copyfileName "QuoteCopy.txt;
String saveFileName "QuoteMorse.txt;
StringBuilder sb new StringBuilder;
try BufferedReader br new BufferedReadernew FileReaderworkingDir fileName
String line ;
while line brreadLine null
sbappendline;
catch FileNotFoundException e
System.out.printworkingDir fileName File Not found";
catch IOException e
eprintStackTrace;
mcencodeSaveToFilesbtoString workingDir saveFileName;
String encodeCopy mcencodesbtoString;
mcdecodeSaveToFileencodeCopy workingDir copyfileName;
Given Interface:
public interface Converter
public void printKeyValuePairs;
public String encodeString textToEncode;
public String decodeString textToDecode;
public boolean decodeSaveToFileString decode, String filename ;
public boolean encodeSaveToFileString 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
:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started