Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssesmentFour
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
william.hill1
AssesmentFour
Commits
e706f6f8
Commit
e706f6f8
authored
Feb 04, 2019
by
william.hill1
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
62 additions
and
14 deletions
+62
-14
AssessmentPartFour.java
src/AssessmentPartFour.java
+62
-14
No files found.
src/AssessmentPartFour.java
View file @
e706f6f8
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filename
)
{
return
0
;
public
int
loadMorseFromFile
(
String
filename
)
{
File
x
=
new
File
(
filename
);
//sets the filename to be the file
BufferedReader
buffer
=
null
;
//internalises the variable
int
lines
=
0
;
//internalises the line count
String
Morse
=
null
;
//internalises the string
try
{
//used to catch exeptions
buffer
=
new
BufferedReader
(
new
FileReader
(
x
));
// allows to read the file
while
((
Morse
=
buffer
.
readLine
())
!=
null
)
{
//repeats this while there is a line available
morseCode
.
add
(
Morse
);
//adds the line into the arraylist
lines
++;
//increases the line count to the amount of lines in the file
}
}
catch
(
IOException
e
)
{
//catches exceptions
e
.
printStackTrace
();
//prints the trace to help debug
}
finally
{
try
{
if
(
buffer
!=
null
)
{
//if the buffer isnt null
buffer
.
close
();
// closes the buffer at the end
}
}
catch
(
FileNotFoundException
e
)
{
//catches exceptions
e
.
printStackTrace
();
//prints the trace
}
catch
(
IOException
e
)
{
//catches exceptions
// TODO Auto-generated catch block
e
.
printStackTrace
();
//prints the trace
}
}
System
.
out
.
println
(
morseCode
);
//prints the morsecode array to help me see if it all worked
return
lines
;
//returns the line count
}
public
String
translateMorse
()
{
return
""
;
public
String
translateMorse
()
{
String
[]
code
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
// the alphebet in morse including space "/"
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
String
[]
Alphabet
=
{
"a"
,
" b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
// the alphebet in english
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
" "
};
String
Converted
=
""
;
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
{
//loops the legnth of the list
for
(
int
j
=
0
;
j
<
code
.
length
;
j
++)
{
//a nested loop looping the legnth of the morse code array
if
(
morseCode
.
get
(
i
).
equals
(
code
[
j
]))
{
//if the arraylist element equals a code array element
Converted
+=
Alphabet
[
j
];
//converted = the position of the code array element in the Alphebet array
}
}
}
morseCode
.
clear
();
//clears previous so it dosent convert the other bit too so if 1 was a and 2 was b it wouldnt return ab it would return b
return
Converted
;
}
}
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