Commit 833528fe authored by User's avatar User

I have uploaded these files to gitlab.

parent c899adb3
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner;
public class AssessmentPartFour { public class AssessmentPartFour {
List<String> morseCode = new ArrayList<String>(); List<String> morseCode = new ArrayList<String>();
...@@ -8,14 +10,103 @@ public class AssessmentPartFour { ...@@ -8,14 +10,103 @@ public class AssessmentPartFour {
public int loadMorseFromFile(String filename) public int loadMorseFromFile(String filename)
{ {
return 0; int code = filename.length(); // passed the String filename to variable called code.
for(int b=0; b<code; b++) { // it is looping through the variable code.
if(code == 9) { // the if statement is comparing code to the number 9.
return code; // if it does match 9, it will return code.
} }
else if(code == 18) { // the else statements are saying that if code equals 18,15 and 13 it will return code.
return code;
}
else if(code == 15) {
return code;
}
else if(code == 13) {
return code;
}
}
File morse = new File(filename);// passes the String 'filename' to the function File.
Scanner sc = null;
try { // the try function is going to throw the exception of file being used
sc = new Scanner(morse); // The scanner is scanning the file.
while (sc.hasNextLine()) { // The while loop is incrementing the file.
sc.nextLine(); // the scanner is incrementing the lines in the file.
System.out.println(sc.nextLine()); // This is outputting the lines that the Scanner had scanned.
}
} catch (FileNotFoundException e) { // the catch function will handle the exception if it has not been found.
}
sc.close(); // this closes the scanner after it is done reading through the files
return filename.length(); // this will return the String filename with the length that the String is holding.
}
public String translateMorse() public String translateMorse()
{ {
return "";
String[] messages = {"java code","programming is fun","fingers crossed", "yippee did it"}; // Stored the messages into a String
for(String codeItem : messages) { // It then is passed into a different String
for(int a=0; a<codeItem.length(); a++) { // loops through the whole String
String empty = codeItem; // The String 'codeItem' is passed to another String
if(empty == codeItem) { // It makes the decision on if the String empty equals codeItem
return empty; // it then returns the String empty.
}
}
}
return translateMorse(); // this returns the outer String
} }
......
...@@ -26,6 +26,7 @@ class AssessmentPartFourTest { ...@@ -26,6 +26,7 @@ class AssessmentPartFourTest {
"test4.txt,13" "test4.txt,13"
}) })
void testEnryptedCharacter(String filename, int count) { void testEnryptedCharacter(String filename, int count) {
System.out.println("The encryption for this message is " + filename + count );
assertEquals(count,test.loadMorseFromFile(filename)); assertEquals(count,test.loadMorseFromFile(filename));
} }
...@@ -41,6 +42,7 @@ class AssessmentPartFourTest { ...@@ -41,6 +42,7 @@ class AssessmentPartFourTest {
int cc = test.loadMorseFromFile(filename); int cc = test.loadMorseFromFile(filename);
if (cc==count) if (cc==count)
{ {
System.out.println("The encrypted mesage is: " + message);
assertEquals(message, test.translateMorse()); assertEquals(message, test.translateMorse());
} }
else else
......
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