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
6d8ed013
Commit
6d8ed013
authored
Dec 10, 2018
by
liam.wadsworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final commit attempt 2
parent
0225d2fd
Pipeline
#468
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
15 deletions
+15
-15
AssessmentPartFour.java
src/AssessmentPartFour.java
+15
-15
No files found.
src/AssessmentPartFour.java
View file @
6d8ed013
...
...
@@ -10,35 +10,35 @@ public class AssessmentPartFour {
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filename
)
{
Scanner
scan
;
morseCode
.
clear
();
File
file
=
new
File
(
filename
);
try
{
scan
=
new
Scanner
(
file
);
{
Scanner
scan
;
//Defines the scanner that will be used for reading the file
morseCode
.
clear
();
//Clears the variable that stores the file so that if the program is rerun, it doesn't keep the old file
File
file
=
new
File
(
filename
);
//Gets the file that will be translated and stores it in a variable
try
{
//This try is used for handling if there is an error reading the file
scan
=
new
Scanner
(
file
);
//Reads the file
}
catch
(
FileNotFoundException
e
)
catch
(
FileNotFoundException
e
)
//A condition that occurs if the file isn't found
{
System
.
out
.
println
(
"Error reading file, exiting program"
);
return
-
1
;
}
String
line
;
String
line
;
//Will be used for storing an individual line from the file
while
(
scan
.
hasNextLine
())
{
line
=
scan
.
nextLine
();
morseCode
.
add
(
line
);
morseCode
.
add
(
line
);
//Adds the line to an arraylist
}
return
morseCode
.
size
();
return
morseCode
.
size
();
//Returns the length of the arraylist
}
public
String
translateMorse
()
{
String
translatedCode
=
""
;
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
String
translatedCode
=
""
;
//A string that will be used to hold the translated message
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
//Loops once for every line in the code
{
char
translatedChar
=
' '
;
switch
(
morseCode
.
get
(
i
))
char
translatedChar
=
' '
;
//An individual character that will be translated
switch
(
morseCode
.
get
(
i
))
//A switch statement that compares the line to every letter in the alphabet
//in morse code and assigns that letter to a variable
{
case
".-"
:
translatedChar
=
'a'
;
break
;
...
...
@@ -93,7 +93,7 @@ public class AssessmentPartFour {
case
"--.."
:
translatedChar
=
'z'
;
break
;
}
translatedCode
=
translatedCode
+
translatedChar
;
translatedCode
=
translatedCode
+
translatedChar
;
//Adds the translated character to the final message string
}
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