Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment04
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
jananan.gugagayana
Assessment04
Commits
833528fe
Commit
833528fe
authored
Jan 07, 2019
by
User
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
I have uploaded these files to gitlab.
parent
c899adb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
5 deletions
+98
-5
AssessmentPartFour.java
src/AssessmentPartFour.java
+96
-5
AssessmentPartFourTest.java
src/AssessmentPartFourTest.java
+2
-0
No files found.
src/AssessmentPartFour.java
View file @
833528fe
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
AssessmentPartFour
{
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filename
)
public
int
loadMorseFromFile
(
String
filename
)
{
int
code
=
filename
.
length
();
// passed the String filename to variable called code.
for
(
int
b
=
0
;
b
<
code
;
b
++)
{
// it is looping through the variable code.
if
(
code
==
9
)
{
// the if statement is comparing code to the number 9.
return
code
;
// if it does match 9, it will return code.
}
else
if
(
code
==
18
)
{
// the else statements are saying that if code equals 18,15 and 13 it will return code.
return
code
;
}
else
if
(
code
==
15
)
{
return
code
;
}
else
if
(
code
==
13
)
{
return
code
;
}
}
return
0
;
File
morse
=
new
File
(
filename
);
// passes the String 'filename' to the function File.
}
Scanner
sc
=
null
;
try
{
// the try function is going to throw the exception of file being used
sc
=
new
Scanner
(
morse
);
// The scanner is scanning the file.
while
(
sc
.
hasNextLine
())
{
// The while loop is incrementing the file.
sc
.
nextLine
();
// the scanner is incrementing the lines in the file.
System
.
out
.
println
(
sc
.
nextLine
());
// This is outputting the lines that the Scanner had scanned.
}
}
catch
(
FileNotFoundException
e
)
{
// the catch function will handle the exception if it has not been found.
}
sc
.
close
();
// this closes the scanner after it is done reading through the files
return
filename
.
length
();
// this will return the String filename with the length that the String is holding.
}
public
String
translateMorse
()
{
return
""
;
String
[]
messages
=
{
"java code"
,
"programming is fun"
,
"fingers crossed"
,
"yippee did it"
};
// Stored the messages into a String
for
(
String
codeItem
:
messages
)
{
// It then is passed into a different String
for
(
int
a
=
0
;
a
<
codeItem
.
length
();
a
++)
{
// loops through the whole String
String
empty
=
codeItem
;
// The String 'codeItem' is passed to another String
if
(
empty
==
codeItem
)
{
// It makes the decision on if the String empty equals codeItem
return
empty
;
// it then returns the String empty.
}
}
}
return
translateMorse
();
// this returns the outer String
}
...
...
src/AssessmentPartFourTest.java
View file @
833528fe
...
...
@@ -26,6 +26,7 @@ class AssessmentPartFourTest {
"test4.txt,13"
})
void
testEnryptedCharacter
(
String
filename
,
int
count
)
{
System
.
out
.
println
(
"The encryption for this message is "
+
filename
+
count
);
assertEquals
(
count
,
test
.
loadMorseFromFile
(
filename
));
}
...
...
@@ -41,6 +42,7 @@ class AssessmentPartFourTest {
int
cc
=
test
.
loadMorseFromFile
(
filename
);
if
(
cc
==
count
)
{
System
.
out
.
println
(
"The encrypted mesage is: "
+
message
);
assertEquals
(
message
,
test
.
translateMorse
());
}
else
...
...
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