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;
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filename
)
{
int
number
=
0
;
morseCode
.
clear
();
int
number
=
0
;
// Create an int to store the number of line
morseCode
.
clear
();
// just to be sure the Array list is clear before start the method
try
{
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
));
Scanner
scanner
=
new
Scanner
(
new
File
(
filename
));
// to open the file
try
{
number
=
0
;
while
(
scanner
.
hasNextLine
())
{
String
line
=
scanner
.
nextLine
();
while
(
scanner
.
hasNextLine
())
{
// to run each line of the file
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
{
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
());
}
...
...
@@ -41,24 +41,24 @@ public class AssessmentPartFour {
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
));
return
new
String
(
to
);
System
.
out
.
println
(
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
alphabet
=
0
;
char
morse
;
// to store the final translation
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'
;
break
;
case
"-..."
:
alphabet
=
'b'
;
...
...
@@ -131,11 +131,11 @@ public class AssessmentPartFour {
break
;
case
"-----"
:
alphabet
=
'0'
;
break
;
case
"/"
:
alphabet
=
' '
;
case
"/"
:
alphabet
=
' '
;
break
;
}
morse
=
alphabet
;
morse
=
alphabet
;
// just to store the letter in a final Char.
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