Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
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
romain.vasseur
assessment part 4
Commits
1fcc2748
Commit
1fcc2748
authored
Dec 10, 2018
by
Romain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final update
parent
f0f2855a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
AssessmentPartFour.java
src/AssessmentPartFour.java
+21
-21
No files found.
src/AssessmentPartFour.java
View file @
1fcc2748
...
@@ -7,29 +7,29 @@ import java.util.Scanner;
...
@@ -7,29 +7,29 @@ import java.util.Scanner;
public
class
AssessmentPartFour
{
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filename
)
{
public
int
loadMorseFromFile
(
String
filename
)
{
int
number
=
0
;
int
number
=
0
;
// Create an int to store the number of line
morseCode
.
clear
();
morseCode
.
clear
();
// just to be sure the Array list is clear before start the method
try
{
try
{
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
));
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
));
// to open the file
try
{
try
{
number
=
0
;
number
=
0
;
while
(
scanner
.
hasNextLine
())
{
while
(
scanner
.
hasNextLine
())
{
// to run each line of the file
String
line
=
scanner
.
nextLine
();
String
line
=
scanner
.
nextLine
();
// create a string with the line of the file
morseCode
.
add
(
line
);
morseCode
.
add
(
line
);
// each line is added in the array list
number
=
morseCode
.
size
();
number
=
morseCode
.
size
();
// number return the length of the array list
}
}
}
finally
{
}
finally
{
scanner
.
close
();
scanner
.
close
();
// close the file
}
}
}
catch
(
FileNotFoundException
ex
)
{
}
catch
(
FileNotFoundException
ex
)
{
// in case if the file is not found
System
.
out
.
println
(
"Erreur --"
+
ex
.
toString
());
System
.
out
.
println
(
"Erreur --"
+
ex
.
toString
());
}
}
...
@@ -41,24 +41,24 @@ public class AssessmentPartFour {
...
@@ -41,24 +41,24 @@ public class AssessmentPartFour {
public
String
translateMorse
()
public
String
translateMorse
()
{
{
char
[]
to
=
new
char
[
morseCode
.
size
()];
char
[]
to
=
new
char
[
morseCode
.
size
()];
// create an array to store each character of the morse code
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
for
(
int
i
=
0
;
i
<
morseCode
.
size
();
i
++)
// to run each character in the array list
{
{
to
[
i
]=
morseToEnglish
(
morseCode
.
get
(
i
));
to
[
i
]=
morseToEnglish
(
morseCode
.
get
(
i
));
// the array take each morse character and translate it in english using a method
}
}
System
.
out
.
println
(
new
String
(
to
));
System
.
out
.
println
(
new
String
(
to
));
return
new
String
(
to
);
return
new
String
(
to
);
// return and create a String from the array
}
}
private
static
char
morseToEnglish
(
String
a
)
private
static
char
morseToEnglish
(
String
a
)
// create a method who translate each morse character in english
{
{
char
morse
;
char
morse
;
// to store the final translation
char
alphabet
=
0
;
char
alphabet
=
0
;
// to store the translation of morse code
switch
(
a
)
{
switch
(
a
)
{
// to assign each morse character to its letter
case
".-"
:
alphabet
=
'a'
;
case
".-"
:
alphabet
=
'a'
;
break
;
break
;
case
"-..."
:
alphabet
=
'b'
;
case
"-..."
:
alphabet
=
'b'
;
...
@@ -131,11 +131,11 @@ public class AssessmentPartFour {
...
@@ -131,11 +131,11 @@ public class AssessmentPartFour {
break
;
break
;
case
"-----"
:
alphabet
=
'0'
;
case
"-----"
:
alphabet
=
'0'
;
break
;
break
;
case
"/"
:
alphabet
=
' '
;
case
"/"
:
alphabet
=
' '
;
break
;
break
;
}
}
morse
=
alphabet
;
morse
=
alphabet
;
// just to store the letter in a final Char.
return
morse
;
return
morse
;
}
}
...
...
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