Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Untoasted_Craven;
- import java.util.ArrayList;
- public class Feedback_1 {
- private static String morseCodeAlphabet = " .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..";
- 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";
- private static String wordToDivide = "brandon";
- public static void main(String[] args) {
- // initialization
- ArrayList<String> splitMorse = splitMorseCode(morseCodeAlphabet);
- ArrayList<String> splitAlphabet = alphabetToList(alphabet);
- ArrayList<String> splitWord = wordToString(wordToDivide);
- String newWord = convertMorseCode(splitMorse, splitAlphabet, splitWord);
- System.out.println(newWord);
- }
- public static ArrayList<String> splitMorseCode(String morseCodeAlphabet) {
- ArrayList<String> result = new ArrayList<String>();
- for (int i = 0; i < 26; i++) {
- String[] placeHolder = morseCodeAlphabet.split(" ");
- result.add(placeHolder[i]);
- }
- return result;
- }
- public static ArrayList<String> alphabetToList(String alphabet) {
- ArrayList<String> result = new ArrayList<String>();
- for (int i = 0; i < 26; i++) {
- String[] placeHolder = alphabet.split(" ");
- result.add(placeHolder[i]);
- }
- return result;
- }
- public static ArrayList<String> wordToString(String wordToDivide) {
- ArrayList<String> result = new ArrayList<String>();
- for (int i = 0; i < wordToDivide.length(); i++) {
- String[] newPlaceHolder = wordToDivide.split("a{0}");
- result.add(newPlaceHolder[i]);
- }
- return result;
- }
- public static String convertMorseCode(ArrayList<String> splitMorse, ArrayList<String> splitAlphabet, ArrayList<String> splitWord) {
- String newWord = "";
- int counterForLetter = 0;
- for (int i = 0; i < 27; i++) {
- if (splitWord.get(counterForLetter).equals(splitAlphabet.get(i))) {
- newWord += splitMorse.get(i);
- counterForLetter++;
- i = 0;
- }
- if (counterForLetter == wordToDivide.length()) {
- break;
- }
- }
- return newWord;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement