Commit 1c505084 authored by Dell's avatar Dell

commit

parent c899adb3
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 static void main(String[] args)
{
List<String> morseCode = new ArrayList<String>();
AssessmentPartFour a=new AssessmentPartFour();
int d=a.loadMorseFromFile("test4.txt");
System.out.println(d);
}
public int loadMorseFromFile(String filename)
public static int loadMorseFromFile(String fileName)
{
char b;
int c=0;
String text = "";
try
return 0;
{
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 static String translateMorse(String txt)
{
char b='h';
int x=0;
String r="";
public String translateMorse()
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
{
return "";
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;
}
......
......@@ -26,7 +26,7 @@ class AssessmentPartFourTest {
"test4.txt,13"
})
void testEnryptedCharacter(String filename, int count) {
assertEquals(count,test.loadMorseFromFile(filename));
assertEquals(count,AssessmentPartFour.loadMorseFromFile(filename));
}
@ParameterizedTest
......@@ -38,10 +38,10 @@ class AssessmentPartFourTest {
"test4.txt,13,yippee did it"
})
void testEncryptedString(String filename, int count, String message) {
int cc = test.loadMorseFromFile(filename);
int cc = AssessmentPartFour.loadMorseFromFile(filename);
if (cc==count)
{
assertEquals(message, test.translateMorse());
assertEquals(message, AssessmentPartFour.translateMorse(message));
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment