Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asignment
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
thomas.unsworth
asignment
Commits
3feac6bd
Commit
3feac6bd
authored
Jan 02, 2019
by
tomun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
part four
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
AssessmentPartFour.java
Assessment04-18/src/AssessmentPartFour.java
+80
-0
No files found.
Assessment04-18/src/AssessmentPartFour.java
0 → 100644
View file @
3feac6bd
import
java.io.BufferedReader
;
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
)
throws
IOException
{
int
numOfLetters
=
0
;
try
{
FileReader
fr
=
new
FileReader
(
filename
);
BufferedReader
in
=
new
BufferedReader
(
fr
);
String
str
;
while
((
str
=
in
.
readLine
())
!=
null
)
{
numOfLetters
+=
1
;
}
in
.
close
();
return
numOfLetters
;
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
System
.
out
.
println
(
"error"
);
return
0
;
}
}
public
String
translateMorse
(
String
filename
,
int
count
)
throws
IOException
{
String
[][]
morseAlphabet
=
{{
".-"
,
"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
translated
=
""
;
int
pos
=
0
;
String
morse
=
""
;
try
{
FileReader
fr
=
new
FileReader
(
filename
);
BufferedReader
in
=
new
BufferedReader
(
fr
);
for
(
int
i
=
0
;
i
<
loadMorseFromFile
(
filename
);
i
++)
{
morse
=
in
.
readLine
();
for
(
int
j
=
0
;
j
<
morseAlphabet
.
length
;
j
++)
{
if
(
morse
.
equals
(
morseAlphabet
[
j
][
0
]))
{
translated
+=
morseAlphabet
[
j
][
1
];
}
}
}
//System.out.println(translated);
in
.
close
();
return
translated
;
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
"error"
);
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