Commit 65993b52 authored by Romain's avatar Romain

update

parent abc9a5be
Pipeline #425 failed with stages
......@@ -21,10 +21,10 @@ public class AssessmentPartFour {
number=0;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);
morseCode.add(line);
// Faites ici votre traitement.
System.out.println(morseCode.size());
number=morseCode.size();
}
......@@ -37,15 +37,123 @@ public class AssessmentPartFour {
}
public String translateMorse()
public String translateMorse(String filename)/*add String filename in () */
{
List<String> morseCode = new ArrayList<String>();
char [] to=new char[loadMorseFromFile(filename)];
try (Scanner scanner = new Scanner(new File(filename))) {
// On boucle sur chaque champ détecté.
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
morseCode.add(line);
return "";
}
for(int i=0;i<morseCode.size();i++)
{
to[i]=morseToEnglish(morseCode.get(i));
}
} catch (FileNotFoundException ex) {
System.out.println("Erreur --" + ex.toString());
}
System.out.println(new String(to));
return new String(to);
}
private static char morseToEnglish(String a)
{
char morse;
char alphabet = 0;
switch(a) {
case ".-" : alphabet = 'a';
break;
case "-...": alphabet= 'b';
break;
case "-.-.": alphabet= 'c';
break;
case "-..": alphabet= 'd';
break;
case ".": alphabet= 'e';
break;
case "..-.": alphabet= 'f';
break;
case "--.": alphabet= 'g';
break;
case "....": alphabet= 'h';
break;
case "..": alphabet= 'i';
break;
case ".---": alphabet= 'j';
break;
case "-.-": alphabet= 'k';
break;
case ".-..": alphabet= 'l';
break;
case "--": alphabet= 'm';
break;
case "-.": alphabet= 'n';
break;
case "---": alphabet= 'o';
break;
case ".--.": alphabet= 'p';
break;
case "--.-": alphabet= 'q';
break;
case ".-.": alphabet= 'r';
break;
case "...": alphabet= 's';
break;
case "-": alphabet= 't';
break;
case "..-": alphabet= 'u';
break;
case "...-": alphabet= 'v';
break;
case ".--": alphabet= 'w';
break;
case "-..-": alphabet= 'x';
break;
case "-.--": alphabet= 'y';
break;
case "--..": alphabet= 'z';
break;
case ".----": alphabet= '1';
break;
case "..---": alphabet= '2';
break;
case "...--": alphabet= '3';
break;
case "....-": alphabet= '4';
break;
case ".....": alphabet= '5';
break;
case "-....": alphabet= '6';
break;
case "--...": alphabet= '7';
break;
case "---..": alphabet= '8';
break;
case "----.": alphabet= '9';
break;
case "-----": alphabet= '0';
break;
case "/": alphabet= ' ';
break;
}
morse=alphabet;
return morse;
}
}
......@@ -41,7 +41,7 @@ class AssessmentPartFourTest {
int cc = test.loadMorseFromFile(filename);
if (cc==count)
{
assertEquals(message, test.translateMorse());
assertEquals(message, test.translateMorse(filename)); // add filename in ()
}
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