Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. package Untoasted_Craven;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Feedback_1 {
  6.  
  7.     private static String morseCodeAlphabet = " .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..";
  8.     private static String alphabet = " 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";
  9.     private static String wordToDivide = "brandon";
  10.  
  11.     public static void main(String[] args) {
  12.         // initialization
  13.         ArrayList<String> splitMorse = splitMorseCode(morseCodeAlphabet);
  14.         ArrayList<String> splitAlphabet = alphabetToList(alphabet);
  15.  
  16.         ArrayList<String> splitWord = wordToString(wordToDivide);
  17.         String newWord = convertMorseCode(splitMorse, splitAlphabet, splitWord);
  18.         System.out.println(newWord);
  19.     }
  20.  
  21.     public static ArrayList<String> splitMorseCode(String morseCodeAlphabet) {
  22.         ArrayList<String> result = new ArrayList<String>();
  23.  
  24.         for (int i = 0; i < 26; i++) {
  25.             String[] placeHolder = morseCodeAlphabet.split(" ");
  26.             result.add(placeHolder[i]);
  27.         }
  28.  
  29.         return result;
  30.     }
  31.  
  32.     public static ArrayList<String> alphabetToList(String alphabet) {
  33.         ArrayList<String> result = new ArrayList<String>();
  34.  
  35.         for (int i = 0; i < 26; i++) {
  36.             String[] placeHolder = alphabet.split(" ");
  37.             result.add(placeHolder[i]);
  38.         }
  39.  
  40.         return result;
  41.     }
  42.  
  43.     public static ArrayList<String> wordToString(String wordToDivide) {
  44.         ArrayList<String> result = new ArrayList<String>();
  45.  
  46.         for (int i = 0; i < wordToDivide.length(); i++) {
  47.             String[] newPlaceHolder = wordToDivide.split("a{0}");
  48.             result.add(newPlaceHolder[i]);
  49.         }
  50.  
  51.         return result;
  52.     }
  53.  
  54.     public static String convertMorseCode(ArrayList<String> splitMorse, ArrayList<String> splitAlphabet, ArrayList<String> splitWord) {
  55.         String newWord = "";
  56.  
  57.         int counterForLetter = 0;
  58.         for (int i = 0; i < 27; i++) {
  59.             if (splitWord.get(counterForLetter).equals(splitAlphabet.get(i))) {
  60.                 newWord += splitMorse.get(i);
  61.                 counterForLetter++;
  62.                 i = 0;
  63.             }
  64.             if (counterForLetter == wordToDivide.length()) {
  65.                 break;
  66.             }
  67.         }
  68.  
  69.         return newWord;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement