From b0788e0249be993d650aa540fae00cdf624f7d4f Mon Sep 17 00:00:00 2001 From: LucasVbr Date: Sat, 30 Oct 2021 22:15:05 +0200 Subject: [PATCH] Tool to convert text to Morse --- .gitignore | 1 + Morse.iml | 11 ++++ out/production/Morse/Morse.class | Bin 0 -> 4943 bytes src/Morse.java | 93 +++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 .gitignore create mode 100644 Morse.iml create mode 100644 out/production/Morse/Morse.class create mode 100644 src/Morse.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61069b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/* \ No newline at end of file diff --git a/Morse.iml b/Morse.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Morse.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Morse/Morse.class b/out/production/Morse/Morse.class new file mode 100644 index 0000000000000000000000000000000000000000..e31193ea9f53bc2e7dab0cf5476b292b75e1190d GIT binary patch literal 4943 zcmaKvd0bT2701tIW|+$`Dvp36iinDA1A>4GD#AEKWCoN$6w&B&c+t^ehRi%{Y`WL9 zP4{$3lQwNryCiLGYfOt)t7)62w&}hvY11}s(|zC4E%tZryH8N~^bg*=^S$Sud$xD) zXDF-7Ey_p7W=7`mI(4h(-~eY5KpI$n;DDM2h$oBRfT48fmbQ>(=sYYHVpWi8Wj|* zn(6Dzx!TWmNfm-bIa^xkr&XK|X{GHDIZdnmRK?JfMP|nH;Bt+hYN-xc8|>_ggb#%J z`-Z{;v7Y`u)a zX?J6L^pu%Ei=Cgeny(@yENf>zGv*UaSQQ4ekRQm>yP6urJvPh>4~ z49$=A;F3Kxk#5+52DY%6X^gc8@G15CX$S2@r;ZuN%uqTNH>}+W>j>VmmXWd$&iYwg znd!;Q7HaoVj0U~5%TGhJThIdaEnM${An!OkluX@_Hai{d{NWB`>MW&|G=lEvl(b(^ zPJK|)0f=3a40KPhzP?^k8~{y(Zw4R;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r9jWcoIbq z^->e{Ppe3=u1F~@6cPSzFt^2yLU~-TD*}h7YO-86Q~vb2um)FVrx?&d97KQeu~QuA ziqxK`t!`xFW=&)SHBX8j9Ih8$`z|%*5a_0id8aeby$^RHO$sItWL3d zX6qfcMzJPl8ywcGSZgfyFjezrB-G(+-vA1+f$j#&5qku0J`$sQ@pn)hg5<+nT$ti8 GmHZE$obzb_ literal 0 HcmV?d00001 diff --git a/src/Morse.java b/src/Morse.java new file mode 100644 index 0000000..585a7eb --- /dev/null +++ b/src/Morse.java @@ -0,0 +1,93 @@ +/* + * Morse, 18/09/2021 + * IUT Rodez 2021, INFO2 TD3 + * pas de copyright, aucun droits + */ + +import java.util.Locale; + +/** + * Outils de conversion en code morse + * + * @author Lucas Vabre + */ +public class Morse { + + private static final int CARATERE = 0; + private static final int CODE = 1; + private static final String DELIMITEUR = " "; + + public static final String[][] TABLE_CONVERSION = { + {"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", "--.."}, {"0", "-----"}, {"1", ".----"}, {"2", "..---"}, + {"3", "...--"}, {"4", "....-"}, {"5", "....."}, {"6", "-...."}, + {"7", "--..."}, {"8", "---.."}, {"9", "----."}, {".", ".-.-.-"}, + {",", "--..--"}, {"'", ".----."}, {"?", "..--.."}, {":", "---..."}, + {"-", "-....-"}, {"/", "-..-."}, {"[", "-.--."}, {"(", "-.--."}, + {"]", "-.--.-"}, {")", "-.--.-"}, {"\"", ".-..-."}, {"_", "..--.-"}, + {"=", "-...-"}, {"+", ".-.-."}, {"@", ".--.-."}, {"Ä", ".-.-"}, + {"Å", ".--.-"}, {"É", "..-.."}, {"Ñ", "--.--"}, {"Ö", "---."}, + {"Ü", "..--"} + }; + + public static String convertStringToMorse(String aConvertir) { + if (aConvertir == null) throw new IllegalArgumentException(); + + aConvertir = aConvertir.toUpperCase(); + StringBuilder resultat = new StringBuilder(); + + for (char caractere : aConvertir.toCharArray()) { + resultat.append(convertCharToMorse(caractere)) + .append(DELIMITEUR); + } + + return resultat.toString().strip(); + } + + public static String convertCharToMorse(char aConvertir) { + char aTester; + for (String[] conversion : TABLE_CONVERSION) { + aTester = conversion[CARATERE].charAt(0); + if (aTester == aConvertir) return conversion[CODE]; + } + return "?"; + } + + public static String convertMorseToString(String aConvertir) { + if (aConvertir == null) throw new IllegalArgumentException(); + + StringBuilder resultat = new StringBuilder(); + + String[] aConvertirSplitted = aConvertir.split(DELIMITEUR); + for (String code : aConvertirSplitted) { + resultat.append(convertMorseToChar(code)); + } + + return resultat.toString(); + } + + public static char convertMorseToChar(String aConvertir) { + String aTester; + for (String[] conversion : TABLE_CONVERSION) { + aTester = conversion[CODE]; + if (aTester.equals(aConvertir)) return conversion[CARATERE].charAt(0); + } + return '?'; + } + + /** + * Start + * + * @param args + */ + public static void main(String[] args) { + String test = "Message"; + + String morse = convertStringToMorse(test); + System.out.println(test + " : " + morse); + } +}