Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming 01 Task 7-8
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
christopher.spray
Programming 01 Task 7-8
Commits
8fcf6172
Commit
8fcf6172
authored
Jan 08, 2019
by
christopher.spray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AssessmentPartFour.java
parent
c899adb3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
1 deletion
+56
-1
AssessmentPartFour.java
src/AssessmentPartFour.java
+56
-1
No files found.
src/AssessmentPartFour.java
View file @
8fcf6172
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
AssessmentPartFour
{
public
class
AssessmentPartFour
{
...
@@ -7,14 +12,64 @@ public class AssessmentPartFour {
...
@@ -7,14 +12,64 @@ public class AssessmentPartFour {
public
int
loadMorseFromFile
(
String
filename
)
public
int
loadMorseFromFile
(
String
filename
)
{
{
morseCode
.
clear
();
//Clear all contents of the ArrayList so it doesn't add them all together
return
0
;
Path
filepath
=
Paths
.
get
(
filename
);
//find the file
String
fileLine
;
//create an empty string
Scanner
sc
=
null
;
//create scanner
try
{
sc
=
new
Scanner
(
filepath
);
//attempt to read the file
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
//if an error is thrown, print Stack Trace
}
while
(
sc
.
hasNextLine
())
{
//while there is a next line
fileLine
=
sc
.
nextLine
();
//fileLine is the current line being read
morseCode
.
add
(
fileLine
);
//add current line to ArrayList
}
return
morseCode
.
size
();
//return the size of the ArrayList morseCode
}
}
public
String
translateMorse
()
public
String
translateMorse
()
{
{
HashMap
<
String
,
Character
>
translation
=
new
HashMap
<>();
//create a hashmap to store morse code and it's alphabetic equivelant
translation
.
put
(
".-"
,
'a'
);
//add morse for a, and a
translation
.
put
(
"-..."
,
'b'
);
//rinse and repeat
translation
.
put
(
"-.-."
,
'c'
);
translation
.
put
(
"-.."
,
'd'
);
translation
.
put
(
"."
,
'e'
);
translation
.
put
(
"..-."
,
'f'
);
translation
.
put
(
"--."
,
'g'
);
translation
.
put
(
"...."
,
'h'
);
translation
.
put
(
".."
,
'i'
);
translation
.
put
(
".---"
,
'j'
);
translation
.
put
(
"-.-"
,
'k'
);
translation
.
put
(
".-.."
,
'l'
);
translation
.
put
(
"--"
,
'm'
);
translation
.
put
(
"-."
,
'n'
);
translation
.
put
(
"---"
,
'o'
);
translation
.
put
(
".--."
,
'p'
);
translation
.
put
(
"--.-"
,
'q'
);
translation
.
put
(
".-."
,
'r'
);
translation
.
put
(
"..."
,
's'
);
translation
.
put
(
"-"
,
't'
);
translation
.
put
(
"..--"
,
'u'
);
translation
.
put
(
"...-"
,
'v'
);
translation
.
put
(
".--"
,
'w'
);
translation
.
put
(
"-..-"
,
'x'
);
translation
.
put
(
"-.--"
,
'y'
);
translation
.
put
(
"--.."
,
'z'
);
translation
.
put
(
"/"
,
' '
);
return
""
;
return
""
;
}
}
...
...
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