Commit 412b1286 authored by ash.brett's avatar ash.brett

Update AssessmentPartFour.java

parent 0d9e639c
...@@ -12,11 +12,11 @@ public class AssessmentPartFour { ...@@ -12,11 +12,11 @@ public class AssessmentPartFour {
{ {
//This section creates a new instance of File called file and reads from filename //This section creates a new instance of File called file and reads from filename
File file = new File(filename); File file = new File(filename);
//This section of the code clears the arraylist morsecode of all elements within effectively setting it to equal nothing //This section of the code clears the ArrayList morsecode of all elements within effectively setting it to equal nothing
morseCode.clear(); morseCode.clear();
//This section of the code sets up a scanner called Read //This section of the code sets up a scanner called Read
Scanner Read; Scanner Read;
//This section of the code tries to run if an error throws up it instead runs the catch code instead //This section of the code tries to run first. If it is unable to it runs the catch code instead
try { try {
//This section states that Read is equal to a new instance of Scanner which reads from the File file //This section states that Read is equal to a new instance of Scanner which reads from the File file
Read = new Scanner(file); Read = new Scanner(file);
...@@ -26,17 +26,17 @@ public class AssessmentPartFour { ...@@ -26,17 +26,17 @@ public class AssessmentPartFour {
while (Read.hasNextLine()) { while (Read.hasNextLine()) {
//This section of the code sets Holder to be equal to Read's next line of input //This section of the code sets Holder to be equal to Read's next line of input
Holder = (Read.nextLine()); Holder = (Read.nextLine());
//This section of the code adds the value of holder to the Arraylist morsecode //This section of the code adds the value of holder to the ArrayList morsecode
morseCode.add(Holder); morseCode.add(Holder);
} }
//This code runs if the code above throws an error //This code runs if the code above errors
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
//Once all the lines of code have been added it returns the size of the arraylist morsecode //Once all the lines of code have been added it returns the size of the ArrayList morsecode
return morseCode.size(); return morseCode.size();
} }
...@@ -52,12 +52,12 @@ public class AssessmentPartFour { ...@@ -52,12 +52,12 @@ public class AssessmentPartFour {
for(String Words:morseCode) { for(String Words:morseCode) {
//This section creates a new string called Result and sets it to be equal to the result of the Method MorseToEnglish //This section creates a new string called Result and sets it to be equal to the result of the Method MorseToEnglish
//This section of code takes in the string Words in order to run the method MorseToEnglish using this value //This section of code takes in the string Words in order to run the Method MorseToEnglish using this value
String Result = MorseToEnglish(Words); String Result = MorseToEnglish(Words);
//This section adds the String Result to the stringBuilder decoded //This section adds the String Result to the StringBuilder decoded
decoded.append(Result); decoded.append(Result);
} }
// //This section of the code returns the value of the stringBuilder decoded in a string //This section of the code returns the value of the stringBuilder decoded in a string
return decoded.toString(); return decoded.toString();
} }
...@@ -66,7 +66,7 @@ public class AssessmentPartFour { ...@@ -66,7 +66,7 @@ public class AssessmentPartFour {
//This is a new method that I created that takes in the string Morse //This is a new method that I created that takes in the string Morse
public String MorseToEnglish(String Morse) { public String MorseToEnglish(String Morse) {
//This is where I create two strings one called alpha containing the english alphabet and the other called morse which contains the morse equivalents //This is where I create two strings one called alpha containing the English alphabet and the other called morse which contains the morse equivalents
String[] alpha = {"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", " "}; String[] alpha = {"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", " "};
String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-","...-" ,".--" ,"-..-", "-.--", "--..", "/"}; String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-","...-" ,".--" ,"-..-", "-.--", "--..", "/"};
//This section of code creates the int i and sets it to 0. it then states that for each time i is less than morse's length increment it by one and then run the code below //This section of code creates the int i and sets it to 0. it then states that for each time i is less than morse's length increment it by one and then run the code below
......
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