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
liam.wadsworth
Assessment 1 Part 4
Commits
fb773fe8
Commit
fb773fe8
authored
Dec 10, 2018
by
liam.wadsworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final push
parent
c899adb3
Pipeline
#464
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
5 deletions
+86
-5
AssessmentPartFour.java
src/AssessmentPartFour.java
+86
-5
No files found.
src/AssessmentPartFour.java
View file @
fb773fe8
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.nio.file.Files
;
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
>();
public
int
loadMorseFromFile
(
String
filename
)
public
int
loadMorseFromFile
(
String
filename
)
{
{
Scanner
scan
;
morseCode
.
clear
();
return
0
;
File
file
=
new
File
(
filename
)
;
try
{
scan
=
new
Scanner
(
file
);
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
"Error reading file, exiting program"
);
return
-
1
;
}
String
line
;
while
(
scan
.
hasNextLine
())
{
line
=
scan
.
nextLine
();
morseCode
.
add
(
line
);
}
return
morseCode
.
size
();
}
}
public
String
translateMorse
()
public
String
translateMorse
()
{
{
return
""
;
String
translatedCode
=
""
;
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
{
char
translatedChar
=
' '
;
switch
(
morseCode
.
get
(
i
))
{
case
".-"
:
translatedChar
=
'a'
;
break
;
case
"-..."
:
translatedChar
=
'b'
;
break
;
case
"-.-."
:
translatedChar
=
'c'
;
break
;
case
"-.."
:
translatedChar
=
'd'
;
break
;
case
"."
:
translatedChar
=
'e'
;
break
;
case
"..-."
:
translatedChar
=
'f'
;
break
;
case
"--."
:
translatedChar
=
'g'
;
break
;
case
"...."
:
translatedChar
=
'h'
;
break
;
case
".."
:
translatedChar
=
'i'
;
break
;
case
".---"
:
translatedChar
=
'j'
;
break
;
case
"-.-"
:
translatedChar
=
'k'
;
break
;
case
".-.."
:
translatedChar
=
'l'
;
break
;
case
"--"
:
translatedChar
=
'm'
;
break
;
case
"-."
:
translatedChar
=
'n'
;
break
;
case
"---"
:
translatedChar
=
'o'
;
break
;
case
".--."
:
translatedChar
=
'p'
;
break
;
case
"--.-"
:
translatedChar
=
'q'
;
break
;
case
".-."
:
translatedChar
=
'r'
;
break
;
case
"..."
:
translatedChar
=
's'
;
break
;
case
"-"
:
translatedChar
=
't'
;
break
;
case
"..-"
:
translatedChar
=
'u'
;
break
;
case
"...-"
:
translatedChar
=
'v'
;
break
;
case
".--"
:
translatedChar
=
'w'
;
break
;
case
"-..-"
:
translatedChar
=
'x'
;
break
;
case
"-.--"
:
translatedChar
=
'y'
;
break
;
case
"--.."
:
translatedChar
=
'z'
;
break
;
}
translatedCode
=
translatedCode
+
translatedChar
;
}
System
.
out
.
println
(
translatedCode
);
return
translatedCode
;
}
}
...
...
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