Page 1 of 1

//JAVA PLEASE FINISH THE MorseConverter.java as required. To store the strings for the letter and Morse code, use two ha

Posted: Mon May 02, 2022 12:20 pm
by answerhappygod
//JAVA
PLEASE FINISH THE MorseConverter.java as
required.
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
Java Please Finish The Morseconverter Java As Required To Store The Strings For The Letter And Morse Code Use Two Ha 1
Java Please Finish The Morseconverter Java As Required To Store The Strings For The Letter And Morse Code Use Two Ha 1 (13.21 KiB) Viewed 51 times
READ THE CODES IN FROM
THE MORSECODETABLE
FILE
•You should pass the
filename into the object
via the constructor (see
main method)
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 ----.
. .-.-.-
, --..--
? ..--..
: ---...
' .----.
Quote2.txt
There are two major products that come out of Berkeley:
LSD and UNIX. We don't believe this to be a coincidence.
Jeremy S. Anderson
Quote2copy.txt
there are two major products that come out of berkeley:
lsd and unix. we don't believe this to be a coincidence. jeremy s.
anderson
Quote2morse.txt
- .... . .-. . .- .-. . - .-- ---
-- .- .--- --- .-. .--. .-. --- -.. ..- -.-. - ... -
.... .- - -.-. --- -- . --- ..- - --- ..-.
-... . .-. -.- . .-.. . -.-- ---... .-.. ...
-..
//Converter.java
public interface Converter {
//public Converter(String encodingfile); << good
idea
/**
* Prints a list of the key values pairs used to encode and
decode strings.
*
*/
public void printKeyValuePairs();

/**
* Encodes a string based on the Key Value Pairs.
* For Example if the encode file contained Morse code
* the letter a would be replaced with .- wherever it
was in the string
* @param textToEncode the String to encode
* @return returns the encoded version of the
string
*/
public String encode(String textToEncode);

/**
* Encodes a string based on the Key Value Pairs.
* For Example if the encode file contained Morse code
.-
* it would be replaced with a wherever it was in the
string
* @param textToDecode the String to decode
* @return returns the decode version of the
string
*/
public String decode(String textToDecode);

//private boolean saveToFile(String textToSave, String saveToFile
)

/**
* Encodes a string based on the Key Value Pairs.
* For Example if the encode file contained Morse code
.-
* it would be replaced with a wherever it was in the
string
* @param textToDecode the String to decode
* @param filename the file to save the decoded string
in
* @return returns true if the file is decoded and
saved successfully
*/
public boolean decodeSaveToFile(String decode, String filename
);

/**
* Encodes a string based on the Key Value Pairs.
* For Example if the encode file contained Morse code
.-
* it would be replaced with a wherever it was in the
string
* @param encode the String to encode
* @param filename the file to save the encoded string
in
* @return returns true if the file is encoded and
saved successfully
*/
public boolean encodeSaveToFile(String encode, String filename
);


}
//Main.java
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Main {
/**
* @param args
*/
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);

}
}
//MorseConverter.java
public class MorseConverter implements Converter {
public MorseConverter(String string) {
// Auto-generated constructor stub
}
@Override
public void printKeyValuePairs() {
// Auto-generated method stub
}
@Override
public String encode(String textToEncode) {
// Auto-generated method stub
return null;
}
@Override
public String decode(String textToDecode) {
// Auto-generated method stub
return null;
}
@Override
public boolean decodeSaveToFile(String decode, String filename)
{
// Auto-generated method stub
return false;
}
@Override
public boolean encodeSaveToFile(String encode, String filename)
{
// Auto-generated method stub
return false;
}
}
private HashMap<String, String> private HashMap<String, String>