Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assignment Part 4
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bran.harvey-chadwi
Assignment Part 4
Commits
28524a7b
Commit
28524a7b
authored
Jan 05, 2019
by
Bran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completed, removed edited unit test and replaced with original, updated
code to work with new test
parent
1a9758f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
29 deletions
+8
-29
AssessmentPartFour.java
src/AssessmentPartFour.java
+6
-23
AssessmentPartFourTest.java
src/AssessmentPartFourTest.java
+2
-6
No files found.
src/AssessmentPartFour.java
View file @
28524a7b
...
...
@@ -32,31 +32,13 @@ public class AssessmentPartFour
return
morseCode
.
size
();
//returns the size of the array string morseCode
}
//////////////////////////////////////////////
public
String
translateMorse
(
String
filename
)
public
String
translateMorse
()
// public String translateMorse(String filename)
{
File
file
=
new
File
(
filename
);
//creates an instance of a file
morseCode
.
clear
();
// clears the contents of morseCode
//creates an array string containing the alphabet in morse code
String
[]
morse
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
String
[]
morse
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
// creates an array string containing each letter of the alphabet in morse code
String
[]
alphabet
=
{
"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"
,
" "
};
//creates an array string containing the alphabet in lower case
Scanner
sc
=
null
;
//Assigns a value of null to the scanner "sc"
try
//creates a try block and attempts to run the code inside it
{
sc
=
new
Scanner
(
file
);
// creates a new scanner and assigns the value of "file" to it
}
catch
(
FileNotFoundException
e
)
// if the scanner cannot assign the value of "file" , run the following
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
// if an exception is met, prints the stack trace of the instance ready for debugging
}
String
lineFromFile
;
//creates a string called lineFromFile
while
(
sc
.
hasNextLine
())
//creates a while loop as long as as sc has another line waiting
{
lineFromFile
=
sc
.
nextLine
();
//stores the next line in the scanner sc
morseCode
.
add
(
lineFromFile
);
// assigns the value of lineFromfile to morsecode
}
//creates an array string containing each letter of the alphabet in lower case
String
message
=
""
;
//creates a string called message and assigns it nothing
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
//creates a for loop where i = 0 and runs for the size of the array morseCode
{
...
...
@@ -69,6 +51,7 @@ public class AssessmentPartFour
}
}
}
return
message
;
//returns the value of message
}
}
\ No newline at end of file
src/AssessmentPartFourTest.java
View file @
28524a7b
...
...
@@ -27,7 +27,6 @@ class AssessmentPartFourTest {
})
void
testEnryptedCharacter
(
String
filename
,
int
count
)
{
assertEquals
(
count
,
test
.
loadMorseFromFile
(
filename
));
test
.
morseCode
.
clear
();
}
@ParameterizedTest
...
...
@@ -39,17 +38,14 @@ class AssessmentPartFourTest {
"test4.txt,13,yippee did it"
})
void
testEncryptedString
(
String
filename
,
int
count
,
String
message
)
{
test
.
morseCode
.
clear
();
int
cc
=
test
.
loadMorseFromFile
(
filename
);
if
(
cc
==
count
)
{
assertEquals
(
message
,
test
.
translateMorse
(
filename
));
assertEquals
(
message
,
test
.
translateMorse
());
}
else
{
fail
(
"File failed to load"
);
}
test
.
morseCode
.
clear
();
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment