import java.io.*; import java.util.Scanner; public class Translate { private char[] Character = new char[36]; private String[] morseValue = new String[36]; private String sentence; public Translate() throws IOException { File morseTxt = new File("morse.txt"); Scanner morseScanner = new Scanner(morseTxt.getAbsoluteFile()); int index = 0; String buffer, morseSentence; while(index <= 36) { buffer = morseScanner.nextLine(); Character[index] = buffer.charAt(0); morseValue[index] = processLine(buffer); index++; } } public void setSentence(String newSentence) { sentence = newSentence.ToUpperCase(); } public String morseSentenceConversion() { String[] morseBuffer = new String[sentence.getLength()]; for(int index = 0; index < sentence.length(); index++) { for(int index2 = 0; index2 < 36; index2++) { if(sentence.charAt(index) == Character[index2]) { morseBuffer[index] = morseValue[index2]; } else if(sentence.charAt(index) == ' ') { morseBuffer[index] = " "; } } } String morseSentence = ""; for(int index = 0; index < sentence.length; index++) { morseSentence += morseBuffer[index]; } return morseSentence; } private String proccesLine(String value) { char[] arrayElements = new char[value.length - 2]; for(int index = 2; index < value.length(); index++) { arrayElements[index - 2] = value.charAt(index); } String newValue = new String(arrayElements); return newValue + " "; } }