Java Programming:
Create a class the implements this interface, the method printkeyvalues is already completed!
This class should encode and decode these quotes already in the files, which are these:
This is the main Method for the program. It is complete and can not be altered.
The program at the end should convert each quote file then convert it back to check the work.
import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Scanner; import java.util.Map. Entry; public class MorseConverter implements Converter { HashMap
encode = new HashMap (); HashMap decode = new HashMap (); public MorseConverter(String encodingFile) throws IOException /* Prints a list of the key values pairs used to encode and decode strings. */ @Override public void printKeyValuePairs() { // TODO Auto-generated method stub * 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 */ for (Entry entry : this.encode.entrySet()) { System.out.println("" + entry.getKey() + "," + entry.getValue()); for(Entry entry : this.decode.entrySet()) ! System.out.println("" + entry.getValue(); @Override public String encode(String.textToEncode) { // TODO Auto-generated method stub * 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 */ return null; @Override public String decode(String.text.ToRecode) { // TODO Auto-generated method stub * 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 return null; @Override public boolean decodeSaveToFile(String decode, String filename) { // TODO Auto-generated method stub * 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 */ return false; @Override public boolean encode SaveToFile(String.encodeString.filename) { // TODO Auto-generated method stub return false; Main.java Converter.java *MorseConverter.java MorseCodeTable.txt x Quote2.txt Quote2Copy.txt Quote2Morse.txt - - O DO VOUWN AUJO 13 m 14 23 24 x 25 y 26 z 27 0 28 HNM 30 314 32 5 33 6 36 9 37... 38,- 39 ? ..--.. 40 :- 41'.---- U Main.java *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt * Quote2 Copy.txt Quote2 Morse.txt 1 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 WN Main.java *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt Quote2 Copy.txt ~ Quote2 Morse.txt 1 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 - Main.java ) *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt Quote2 Copy.txt Quote2 Morse.txt X ..-- .-..-..------ ....---- .--. ........... ----- 1. - - ... . .-.. . . - - - .... .. . - --- - ... - - - - --- -. -.-. - . . -. -.-. . -.-.- --- - - - -- - -- - -- - - - - - - - --- public class Main { /** * @param args */ public static void main(String[] args) { MorseConverter mc = new MorseConverter("MorseCode Table.txt"); String workingDir = System.getProperty("user.dir") + "/"; mc.printKeyValuePairs(); String fileName = "Quote2.txt"; String copy fileName = "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); sering deso de copil den ene del sitostning')'s covers evane import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Scanner; import java.util.Map. Entry; public class MorseConverter implements Converter { HashMap encode = new HashMap (); HashMap decode = new HashMap (); public MorseConverter(String encodingFile) throws IOException /* Prints a list of the key values pairs used to encode and decode strings. */ @Override public void printKeyValuePairs() { // TODO Auto-generated method stub * 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 */ for (Entry entry : this.encode.entrySet()) { System.out.println("" + entry.getKey() + "," + entry.getValue()); for(Entry entry : this.decode.entrySet()) ! System.out.println("" + entry.getValue(); @Override public String encode(String.textToEncode) { // TODO Auto-generated method stub * 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 */ return null; @Override public String decode(String.text.ToRecode) { // TODO Auto-generated method stub * 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 return null; @Override public boolean decodeSaveToFile(String decode, String filename) { // TODO Auto-generated method stub * 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 */ return false; @Override public boolean encode SaveToFile(String.encodeString.filename) { // TODO Auto-generated method stub return false; Main.java Converter.java *MorseConverter.java MorseCodeTable.txt x Quote2.txt Quote2Copy.txt Quote2Morse.txt - - O DO VOUWN AUJO 13 m 14 23 24 x 25 y 26 z 27 0 28 HNM 30 314 32 5 33 6 36 9 37... 38,- 39 ? ..--.. 40 :- 41'.---- U Main.java *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt * Quote2 Copy.txt Quote2 Morse.txt 1 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 WN Main.java *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt Quote2 Copy.txt ~ Quote2 Morse.txt 1 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 - Main.java ) *Converter.java *MorseConverter.java MorseCodeTable.txt Quote2.txt Quote2 Copy.txt Quote2 Morse.txt X ..-- .-..-..------ ....---- .--. ........... ----- 1. - - ... . .-.. . . - - - .... .. . - --- - ... - - - - --- -. -.-. - . . -. -.-. . -.-.- --- - - - -- - -- - -- - - - - - - - --- public class Main { /** * @param args */ public static void main(String[] args) { MorseConverter mc = new MorseConverter("MorseCode Table.txt"); String workingDir = System.getProperty("user.dir") + "/"; mc.printKeyValuePairs(); String fileName = "Quote2.txt"; String copy fileName = "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); sering deso de copil den ene del sitostning')'s covers evane