Question: I have a two value arrayList that stores both the letters of the alphabet and their equivalent morse code symbols. This is an assignment requirement.

I have a two value arrayList that stores both the letters of the alphabet and their equivalent morse code symbols. This is an assignment requirement. I am trying to compare my input sentence to the arrayList and translate to Morse Code. Here is what I have, but can't figure out the compare portion. Here is my initializeSymbols method which is working and storing all values of letter and symbol. And here is my translateSentence method which is not yet functioning.

private void initializeSymbols(String inputFileName) { morseCodeSymbols = new ArrayList(); String inputLine = ""; String letter = ""; String symbol = ""; try { scannerIn = new Scanner(new File(inputFileName)); while (scannerIn.hasNext()) { inputLine = scannerIn.nextLine(); letter = inputLine.substring(0, inputLine.indexOf(' ')); symbol = inputLine.substring(inputLine.indexOf(' ') + 1); MorseCodeSymbol input = new MorseCodeSymbol(letter, symbol); morseCodeSymbols.add(input); //System.out.println(input.toString()); } MorseCodeSymbol input = new MorseCodeSymbol(" "," "); morseCodeSymbols.add(input); } catch (Exception ex) { } } 
public void translateSentence(String inputString) { sentence = inputString; for (int i = 0; i < sentence.length(); i++) { String letter = String.valueOf(sentence.charAt(i)); for (int j = 0; j < morseCodeSymbols.size(); j++) { if (morseCodeSymbols.get(j).equals(letter)) { translation += morseCodeSymbols.get(j + 1); } } } System.out.println("Translation: " + translation); } 

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!