Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Part04
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
Assessment
Part04
Commits
aafe3ea0
Commit
aafe3ea0
authored
Jan 03, 2019
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12:30 03/01/19
parent
1cbc0815
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
43 deletions
+32
-43
AssessmentPartFour.java
src/AssessmentPartFour.java
+32
-43
No files found.
src/AssessmentPartFour.java
View file @
aafe3ea0
...
...
@@ -4,16 +4,11 @@ import java.io.*;
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
//COMMENT THIS A LOT BETTER
public
int
loadMorseFromFile
(
String
filename
)
{
...
...
@@ -43,57 +38,51 @@ public class AssessmentPartFour
//MOVE THE .GET INTO IT'S OWN VARIABLE.
public
String
translateMorse
()
{
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
{
System
.
out
.
println
(
morseCode
.
get
(
i
)
+
" "
+
(
morseCode
.
get
(
i
)).
length
());
}
String
strTranslated
=
"strTranslated "
;
String
strTranslated
=
""
;
String
[][]
strMorseArray
=
{{
" "
,
"E"
,
"T"
},
// have 1 char
{
"/"
,
"."
,
"-"
},
{
"A"
,
"I"
,
"N"
,
"M"
},
// have 2 char
{
".-"
,
".."
,
"-."
,
"--"
},
{
"D"
,
"G"
,
"K"
,
"O"
,
"R"
,
"S"
,
"U"
,
"W"
},
// have 3 char
{
"-.."
,
"--."
,
"-.-"
,
"---"
,
".-."
,
"..."
,
"..-"
,
".--"
},
{
"B"
,
"C"
,
"F"
,
"H"
,
"J"
,
"L"
,
"P"
,
"Q"
,
"V"
,
"X"
,
"Y"
,
"Z"
},
// have 4 char
{
"-..."
,
"-.-."
,
"..-."
,
"...."
,
".---"
,
".-.."
,
".--."
,
"--.-"
,
"..._"
,
"-..-"
,
"-.--"
,
"--.."
},
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
},
// have 5 char
{
".----"
,
"..---"
,
"...--"
,
"....-"
,
"....."
,
"-...."
,
"--..."
,
"---.."
,
"----."
,
"-----"
}};
//morse-letter lookup table, ordered by morse code length
/* 0 */
{{
" "
,
"E"
,
"T"
},
// have 1 char
/* 1 */
{
"/"
,
"."
,
"-"
},
/* 2 */
{
"A"
,
"I"
,
"N"
,
"M"
},
// have 2 char
/* 3 */
{
".-"
,
".."
,
"-."
,
"--"
},
/* 4 */
{
"D"
,
"G"
,
"K"
,
"O"
,
"R"
,
"S"
,
"U"
,
"W"
},
// have 3 char
/* 5 */
{
"-.."
,
"--."
,
"-.-"
,
"---"
,
".-."
,
"..."
,
"..-"
,
".--"
},
/* 6 */
{
"B"
,
"C"
,
"F"
,
"H"
,
"J"
,
"L"
,
"P"
,
"Q"
,
"V"
,
"X"
,
"Y"
,
"Z"
},
// have 4 char
/* 7 */
{
"-..."
,
"-.-."
,
"..-."
,
"...."
,
".---"
,
".-.."
,
".--."
,
"--.-"
,
"...-"
,
"-..-"
,
"-.--"
,
"--.."
},
/* 8 */
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
},
// have 5 char
/* 9 */
{
".----"
,
"..---"
,
"...--"
,
"....-"
,
"....."
,
"-...."
,
"--..."
,
"---.."
,
"----."
,
"-----"
}};
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
//loops through each morse word within list (which has been taken from file)
{
String
strMorseLetter
;
int
x
=
(((
morseCode
.
get
(
i
)).
length
())
*
2
)
-
1
;
//length of the morse input, times 2, minus 1 is the x co-ordinate of morse code within the array.
for
(
int
y
=
0
;
y
<
strMorseArray
[
x
].
length
;
y
++)
//loop through to identify y co-ordinate
{
System
.
out
.
println
(
"something"
);
System
.
out
.
println
(
strMorseArray
[
x
-
1
][
y
]);
if
(
strMorseArray
[
x
][
y
].
contains
(
morseCode
.
get
(
i
)))
//contains runs fractionally faster than equals.
//only checks against morse code which is the same length, so ".." containing "." is not an issue.
{
strTranslated
.
concat
(
strMorseArray
[
x
-
1
][
y
]);
strMorseArray
[
x
-
1
][
y
].
concat
(
strTranslated
);
strTranslated
=
strTranslated
.
concat
(
strMorseArray
[
x
-
1
][
y
]);
//x minus one = corresponding translation of morse code within the array
//adding recently matched letter to translated string
break
;
}
}
}
//NEED TO SORT OUT LOOPS. WHY HAVE I DIVIDED THE MORSE ARRAY LIKE THIS AGAIN? WHY AREN'T MY STRINGS CONCATNATING?
System
.
out
.
println
(
strTranslated
);
return
""
;
strTranslated
=
strTranslated
.
toLowerCase
();
//converting to lowercase to comply with unit test
System
.
out
.
println
(
"strTranslated = "
+
strTranslated
);
return
strTranslated
;
}
}
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