Commit fb773fe8 authored by liam.wadsworth's avatar liam.wadsworth

final push

parent c899adb3
Pipeline #464 canceled with stages
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class AssessmentPartFour {
List<String> morseCode = new ArrayList<String>();
public int loadMorseFromFile(String filename)
{
return 0;
{Scanner scan;
morseCode.clear();
File file = new File(filename);
try {
scan = new Scanner(file);
}
catch(FileNotFoundException e)
{
System.out.println("Error reading file, exiting program");
return -1;
}
String line;
while(scan.hasNextLine())
{
line = scan.nextLine();
morseCode.add(line);
}
return morseCode.size();
}
public String translateMorse()
{
return "";
String translatedCode = "";
for(int i = 0; i < morseCode.size(); i++)
{
char translatedChar = ' ';
switch(morseCode.get(i))
{
case".-": translatedChar = 'a';
break;
case"-...": translatedChar = 'b';
break;
case"-.-.": translatedChar = 'c';
break;
case"-..": translatedChar = 'd';
break;
case".": translatedChar = 'e';
break;
case"..-.": translatedChar = 'f';
break;
case"--.": translatedChar = 'g';
break;
case"....": translatedChar = 'h';
break;
case"..": translatedChar = 'i';
break;
case".---": translatedChar = 'j';
break;
case"-.-": translatedChar = 'k';
break;
case".-..": translatedChar = 'l';
break;
case"--": translatedChar = 'm';
break;
case"-.": translatedChar = 'n';
break;
case"---": translatedChar = 'o';
break;
case".--.": translatedChar = 'p';
break;
case"--.-": translatedChar = 'q';
break;
case".-.": translatedChar = 'r';
break;
case"...": translatedChar = 's';
break;
case"-": translatedChar = 't';
break;
case"..-": translatedChar = 'u';
break;
case"...-": translatedChar = 'v';
break;
case".--": translatedChar = 'w';
break;
case"-..-": translatedChar = 'x';
break;
case"-.--": translatedChar = 'y';
break;
case"--..": translatedChar = 'z';
break;
}
translatedCode = translatedCode + translatedChar;
}
System.out.println(translatedCode);
return translatedCode;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment