Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class rektop
- {
- public static String[] charCreator(String s)
- {
- String[] charHolder = new String[s.length()];
- for(int i=0; i < charHolder.length; i++)
- {
- Character currentChar = s.charAt(i);
- String charStringed = String.valueOf(currentChar);
- charHolder[i] = charStringed;
- }
- return charHolder;
- }
- public static String[] morseCreator(ArrayList<String> s)
- {
- String[] morse = new String[s.size()];
- for (int i=0; i<s.size(); i++)
- {
- String currentWordAt = s.get(i);
- morse[i] = currentWordAt;
- System.out.println(currentWordAt);
- }
- return morse;
- }
- public static String[] morseCode(String[] getChars)
- {
- String[] finalAnswer = new String[getChars.length];
- for(int i=0; i < getChars.length; i++)
- {
- switch(getChars[i])
- {
- case "a":
- String a = ".- ";
- finalAnswer[i] = a;
- break;
- case "b":
- String b = "-... ";
- finalAnswer[i] = b;
- break;
- case "c":
- String c = "-.-. ";
- finalAnswer[i] = c;
- break;
- case "d":
- String d = "-.. ";
- finalAnswer[i] = (d);
- break;
- case "e":
- String e = ". ";
- finalAnswer[i] = (e);
- break;
- case "f":
- String f = "..-. ";
- finalAnswer[i] = (f);
- break;
- case "g":
- String g = "--. ";
- finalAnswer[i] = (g);
- break;
- case "h":
- String h = ".... ";
- finalAnswer[i] = (h);
- break;
- case "i":
- String ii = ".. ";
- finalAnswer[i] = (ii);
- break;
- case "j":
- String j = ".--- ";
- finalAnswer[i] = (j);
- break;
- case "k":
- String k = "-.- ";
- finalAnswer[i] = (k);
- break;
- case "l":
- String l = ".-.. ";
- finalAnswer[i] = (l);
- break;
- case "m":
- String m = "-- ";
- finalAnswer[i] = (m);
- break;
- case "n":
- String n = "-. ";
- finalAnswer[i] = (n);
- break;
- case "o":
- String o = "--- ";
- finalAnswer[i] = (o);
- break;
- case "p":
- String p = ".--. ";
- finalAnswer[i] = (p);
- break;
- case "q":
- String q = "--.- ";
- finalAnswer[i] = (q);
- break;
- case "r":
- String r = ".-. ";
- finalAnswer[i] = (r);
- break;
- case "s":
- String s = "... ";
- finalAnswer[i] = (s);
- break;
- case "t":
- String t = "- ";
- finalAnswer[i] = (t);
- break;
- case "u":
- String u = "..- ";
- finalAnswer[i] = (u);
- break;
- case "v":
- String v = "...- ";
- finalAnswer[i] = (v);
- break;
- case "w":
- String w = ".-- ";
- finalAnswer[i] = (w);
- break;
- case "x":
- String x = "-..- ";
- finalAnswer[i] = (x);
- break;
- case "y":
- String y = "-.-- ";
- finalAnswer[i] = (y);
- break;
- case "z":
- String z = "--.. ";
- finalAnswer[i] = (z);
- break;
- case " ":
- String space = " ";
- finalAnswer[i] = space;
- break;
- default:
- System.out.println("Not a letter!");
- break;
- }
- }
- return finalAnswer;
- }
- public static void main(String[] args)
- {
- boolean run = true;
- while(run == true)
- {
- String blankSpace = " ";
- Scanner choiceSelection = new Scanner(System.in);
- System.out.println("(1) Translate into morse code");
- System.out.println("(2) Translate from morse code");
- System.out.println("(3) Exit Program");
- String choice = choiceSelection.next();
- while (choice.equals("2") && run == true)
- {
- System.out.println("You chose to translate from morse code!");
- System.out.println("Enter morse code in, words separated by spaces.");
- Scanner getInput = new Scanner(System.in);
- ArrayList<String> wordList = new ArrayList<String>();
- while(getInput.hasNext())
- {
- String currentWord = getInput.next();
- wordList.add(currentWord);
- System.out.println("currentWord=" + currentWord);
- wordList.add(blankSpace);
- System.out.println(wordList);
- }
- getInput.close();
- System.out.println(wordList);
- System.out.println("test");
- String[] finalAns = morseCreator(wordList);
- System.out.println("size" + finalAns.length);
- for(int i=0; i<finalAns.length; i++)
- {
- System.out.println("gggg" + finalAns[i]);
- }
- run = false;
- break;
- }
- choiceSelection.close();
- System.out.println("1/2/3?");
- Scanner newChoiceSelection = new Scanner(System.in);
- String newChoice = newChoiceSelection.next();
- if (choice.equals("1"))
- {
- System.out.println("You chose to translate into morse code!");
- System.out.println("Enter Word: ");
- @SuppressWarnings("resource")
- Scanner wordGet = new Scanner(System.in);
- String word = wordGet.nextLine();
- String[] charString = (charCreator(word));
- String[] finalOutput = morseCode(charString);
- for (int i=0; (i <= finalOutput.length-1); i++)
- System.out.print(finalOutput[i]);
- System.out.println("Would you like to continue?(Y//N)");
- @SuppressWarnings("resource")
- Scanner grabAns = new Scanner(System.in);
- String ans = grabAns.nextLine();
- if (ans.equalsIgnoreCase("y"))
- continue;
- else if (ans.equalsIgnoreCase("n"))
- {
- System.out.println("Thanks for using the program!");
- run = false;
- continue;
- }
- while(!ans.equals("y") && (!ans.equals("n")))
- {
- @SuppressWarnings("resource")
- Scanner newScanner = new Scanner(System.in);
- System.out.println("Invalid choice, select a correct one!");
- System.out.println("Would you like to continue?(Y//N)");
- ans = newScanner.nextLine();
- }
- if (ans.equalsIgnoreCase("n"))
- {
- System.out.println("Thanks for using the program!");
- run = false;
- continue;
- }
- }
- if (choice.equals("3"))
- {
- run = false;
- System.out.println("Thanks for using the program!");
- continue;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement