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
nouman.ashraf
Assessment04
Commits
1c505084
Commit
1c505084
authored
Jan 07, 2019
by
Dell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
c899adb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
12 deletions
+98
-12
AssessmentPartFour.java
src/AssessmentPartFour.java
+95
-9
AssessmentPartFourTest.java
src/AssessmentPartFourTest.java
+3
-3
No files found.
src/AssessmentPartFour.java
View file @
1c505084
import
java.util.ArrayList
;
import
java.util.List
;
import
java.awt.List
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
org.omg.CORBA.Environment
;
public
class
AssessmentPartFour
{
public
class
AssessmentPartFour
{
public
static
void
main
(
String
[]
args
)
{
AssessmentPartFour
a
=
new
AssessmentPartFour
();
int
d
=
a
.
loadMorseFromFile
(
"test4.txt"
);
System
.
out
.
println
(
d
);
}
List
<
String
>
morseCode
=
new
ArrayList
<
String
>();
public
int
loadMorseFromFile
(
String
filen
ame
)
public
static
int
loadMorseFromFile
(
String
fileN
ame
)
{
{
char
b
;
int
c
=
0
;
String
text
=
""
;
return
0
;
try
{
text
=
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
fileName
)));
//Giving Path to that file on which we want to perform Encrption
// and converting text file to String.
//Loading File
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
for
(
int
i
=
0
;
i
<
text
.
length
();
i
++)
// In for loop we will check that how many lines are in the Morse code
{
b
=
text
.
charAt
(
i
);
int
l
=((
char
)
b
);
if
(
l
==
10
)
// 10 is the ASCCII code of LineBreak or NewLine
{
c
++;
}
}
String
p
=
translateMorse
(
text
);
//calling translateMorse function and giving text as String argument
System
.
out
.
println
(
p
);
return
c
;
}
}
public
String
translateMorse
()
public
static
String
translateMorse
(
String
txt
)
{
{
return
""
;
char
b
=
'h'
;
int
x
=
0
;
String
r
=
""
;
String
[]
m
=
{
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
// Morse code for Alphabets and Space
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
,
"/"
};
String
[]
al
=
{
"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
l
=
""
;
for
(
int
i
=
0
;
i
<
txt
.
length
();
i
++)
//for loop iterates acording to lentgh of text length
{
b
=
txt
.
charAt
(
i
);
x
=(
char
)
b
;
if
(
x
==
10
)
//in morse code every Alphabet was on new Line that's why i use 10
{
for
(
int
j
=
0
;
j
<
27
;
j
++)
// Alphabets and Space length
{
if
(
r
.
equals
(
m
[
j
]))
// comparing morse code of String Array ( m ) to new String
{
l
+=
al
[
j
];
}
}
r
=
""
;
continue
;
// used continue to go at start of loop
}
r
=
r
+
txt
.
charAt
(
i
);
}
return
r
;
}
}
}
}
src/AssessmentPartFourTest.java
View file @
1c505084
...
@@ -26,7 +26,7 @@ class AssessmentPartFourTest {
...
@@ -26,7 +26,7 @@ class AssessmentPartFourTest {
"test4.txt,13"
"test4.txt,13"
})
})
void
testEnryptedCharacter
(
String
filename
,
int
count
)
{
void
testEnryptedCharacter
(
String
filename
,
int
count
)
{
assertEquals
(
count
,
test
.
loadMorseFromFile
(
filename
));
assertEquals
(
count
,
AssessmentPartFour
.
loadMorseFromFile
(
filename
));
}
}
@ParameterizedTest
@ParameterizedTest
...
@@ -38,10 +38,10 @@ class AssessmentPartFourTest {
...
@@ -38,10 +38,10 @@ class AssessmentPartFourTest {
"test4.txt,13,yippee did it"
"test4.txt,13,yippee did it"
})
})
void
testEncryptedString
(
String
filename
,
int
count
,
String
message
)
{
void
testEncryptedString
(
String
filename
,
int
count
,
String
message
)
{
int
cc
=
test
.
loadMorseFromFile
(
filename
);
int
cc
=
AssessmentPartFour
.
loadMorseFromFile
(
filename
);
if
(
cc
==
count
)
if
(
cc
==
count
)
{
{
assertEquals
(
message
,
test
.
translateMorse
(
));
assertEquals
(
message
,
AssessmentPartFour
.
translateMorse
(
message
));
}
}
else
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