Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4.  
  5. class Morse {
  6.  
  7. public HashMap<String, String> morseMap = new HashMap<String, String>();
  8.  
  9. public Morse() {
  10. morseMap.put("-.-.--", "!");
  11. morseMap.put("....-", "4");
  12. morseMap.put("..--..", "?");
  13. morseMap.put("--..--", ");");
  14. morseMap.put(".-.-.-", ".");
  15. morseMap.put("..---", "2");
  16. morseMap.put("...--", "3");
  17. morseMap.put("--...", "7");
  18. morseMap.put("-....", "6");
  19. morseMap.put(".....", "5");
  20. morseMap.put("---..", "8");
  21. morseMap.put("-...", "B");
  22. morseMap.put("----.", "9");
  23. morseMap.put(".--.", "P");
  24. morseMap.put("-----", "0");
  25. morseMap.put("--..", "Z");
  26. morseMap.put("-.--", "Y");
  27. morseMap.put("-..-", "X");
  28. morseMap.put("-.-.", "C");
  29. morseMap.put("...-", "V");
  30. morseMap.put(".----", "1");
  31. morseMap.put("..-.", "F");
  32. morseMap.put("....", "H");
  33. morseMap.put(".---", "J");
  34. morseMap.put("--.-", "Q");
  35. morseMap.put("-..-.", "/");
  36. morseMap.put(".-..", "L");
  37. morseMap.put("...", "S");
  38. morseMap.put("---", "O");
  39. morseMap.put("-.-", "K");
  40. morseMap.put(".-.", "R");
  41. morseMap.put("..-", "U");
  42. morseMap.put("-..", "D");
  43. morseMap.put(".--", "W");
  44. morseMap.put("--.", "G");
  45. morseMap.put("-.", "N");
  46. morseMap.put("--", "M");
  47. morseMap.put("..", "I");
  48. morseMap.put(".-", "A");
  49. morseMap.put("-", "T");
  50. morseMap.put(".", "E");
  51. }
  52.  
  53. // Votre code ici
  54.  
  55. public String convert(String input){
  56. String motDuMessage = null;
  57. String message=null;
  58. String chaine = input;
  59. String[] chaineDecoupeParMot = chaine.split(" ");
  60. message="";
  61.  
  62. for(int i = 0; i<(chaineDecoupeParMot.length); i++) {
  63. if (i==0)
  64. {
  65. motDuMessage = "";
  66. }
  67. else {
  68. motDuMessage = " ";
  69. }
  70. String[] chaineDecoupeParLettre = chaineDecoupeParMot[i].split(" ");
  71. String motEnCours=chaineDecoupeParLettre[i];
  72.  
  73. for (int j = 0; j < ((motEnCours.length())+1); j++) {
  74. String actualLettre = (chaineDecoupeParLettre[j]);
  75. String morseCar = morseMap.get(actualLettre).toString();
  76. motDuMessage += morseCar;
  77. }
  78. message =message + motDuMessage;
  79. }
  80. System.out.println(message);
  81.  
  82.  
  83. return message;
  84. }
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement