Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment 1 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
jack.ellis
Assessment 1 Part 4
Commits
e2b0e32b
Commit
e2b0e32b
authored
Dec 10, 2018
by
jack.ellis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
10/12
parent
c899adb3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
8 deletions
+82
-8
AssessmentPartFour.java
src/AssessmentPartFour.java
+77
-7
AssessmentPartFourTest.java
src/AssessmentPartFourTest.java
+5
-1
No files found.
src/AssessmentPartFour.java
View file @
e2b0e32b
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.io.*
;
import
java.util.Scanner
;
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
//
public
int
loadMorseFromFile
(
String
filename
)
{
File
file
=
new
File
(
filename
);
morseCode
.
clear
();
Scanner
sc
=
null
;
try
{
sc
=
new
Scanner
(
file
);
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
String
lineFromFile
;
while
(
sc
.
hasNextLine
())
{
lineFromFile
=
sc
.
nextLine
();
morseCode
.
add
(
lineFromFile
);
return
0
;
}
return
morseCode
.
size
();
}
public
String
translateMorse
()
public
String
translateMorse
(
String
filename
)
{
return
""
;
File
file
=
new
File
(
filename
);
morseCode
.
clear
();
String
[]
morse
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
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"
,
" "
};
Scanner
sc
=
null
;
try
{
sc
=
new
Scanner
(
file
);
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
String
lineFromFile
;
while
(
sc
.
hasNextLine
())
{
lineFromFile
=
sc
.
nextLine
();
morseCode
.
add
(
lineFromFile
);
}
///////////////////////////////////
String
message
=
""
;
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
{
for
(
int
x
=
0
;
x
<
alphabet
.
length
;
x
++)
{
// System.out.println("["+morseCode.get(i)+ "] :: ["+ morse[x] + "]");
if
(
morseCode
.
get
(
i
).
equals
(
morse
[
x
]))
{
morseCode
.
set
(
i
,
alphabet
[
x
]
);
message
+=
alphabet
[
x
];
}
}
}
///////////////////////////////////
System
.
out
.
println
(
message
);
return
message
;
}
}
src/AssessmentPartFourTest.java
View file @
e2b0e32b
...
...
@@ -27,6 +27,7 @@ class AssessmentPartFourTest {
})
void
testEnryptedCharacter
(
String
filename
,
int
count
)
{
assertEquals
(
count
,
test
.
loadMorseFromFile
(
filename
));
test
.
morseCode
.
clear
();
}
@ParameterizedTest
...
...
@@ -38,14 +39,17 @@ 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
());
assertEquals
(
message
,
test
.
translateMorse
(
filename
));
}
else
{
fail
(
"File failed to load"
);
}
test
.
morseCode
.
clear
();
}
}
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