Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Ash Brett Assessment 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
ash.brett
Ash Brett Assessment part 4
Commits
412b1286
Commit
412b1286
authored
Jan 03, 2019
by
ash.brett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AssessmentPartFour.java
parent
0d9e639c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
AssessmentPartFour.java
src/AssessmentPartFour.java
+9
-9
No files found.
src/AssessmentPartFour.java
View file @
412b1286
...
...
@@ -12,11 +12,11 @@ public class AssessmentPartFour {
{
//This section creates a new instance of File called file and reads from filename
File
file
=
new
File
(
filename
);
//This section of the code clears the
arrayl
ist morsecode of all elements within effectively setting it to equal nothing
//This section of the code clears the
ArrayL
ist morsecode of all elements within effectively setting it to equal nothing
morseCode
.
clear
();
//This section of the code sets up a scanner called Read
Scanner
Read
;
//This section of the code tries to run
if an error throws up it instead
runs the catch code instead
//This section of the code tries to run
first. If it is unable to it
runs the catch code instead
try
{
//This section states that Read is equal to a new instance of Scanner which reads from the File file
Read
=
new
Scanner
(
file
);
...
...
@@ -26,17 +26,17 @@ public class AssessmentPartFour {
while
(
Read
.
hasNextLine
())
{
//This section of the code sets Holder to be equal to Read's next line of input
Holder
=
(
Read
.
nextLine
());
//This section of the code adds the value of holder to the Array
l
ist morsecode
//This section of the code adds the value of holder to the Array
L
ist morsecode
morseCode
.
add
(
Holder
);
}
//This code runs if the code above
throws an error
//This code runs if the code above
errors
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
//Once all the lines of code have been added it returns the size of the
arrayl
ist morsecode
//Once all the lines of code have been added it returns the size of the
ArrayL
ist morsecode
return
morseCode
.
size
();
}
...
...
@@ -52,12 +52,12 @@ public class AssessmentPartFour {
for
(
String
Words:
morseCode
)
{
//This section creates a new string called Result and sets it to be equal to the result of the Method MorseToEnglish
//This section of code takes in the string Words in order to run the m
ethod MorseToEnglish using this value
//This section of code takes in the string Words in order to run the M
ethod MorseToEnglish using this value
String
Result
=
MorseToEnglish
(
Words
);
//This section adds the String Result to the
s
tringBuilder decoded
//This section adds the String Result to the
S
tringBuilder decoded
decoded
.
append
(
Result
);
}
//
//This section of the code returns the value of the stringBuilder decoded in a string
//This section of the code returns the value of the stringBuilder decoded in a string
return
decoded
.
toString
();
}
...
...
@@ -66,7 +66,7 @@ public class AssessmentPartFour {
//This is a new method that I created that takes in the string Morse
public
String
MorseToEnglish
(
String
Morse
)
{
//This is where I create two strings one called alpha containing the e
nglish alphabet and the other called morse which contains the morse equivalents
//This is where I create two strings one called alpha containing the E
nglish alphabet and the other called morse which contains the morse equivalents
String
[]
alpha
=
{
"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"
,
" "
};
String
[]
morse
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
//This section of code creates the int i and sets it to 0. it then states that for each time i is less than morse's length increment it by one and then run the code below
...
...
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