I am doing a project that converts a string into morse code. I have most of it down except for that fact that I cannot get it to keep repeating so I tried inserting another while loop in the main method but i keep getting errors with my code and I need to insert a | in between each space but I have been unable to do that either. The following is my code so far if anyone has any tips I would greatly appreciate it.
import java.util.*; public class MorseCodeProj { public String Conversion(String s1){ String result = ""; StringTokenizer tokens = new StringTokenizer(s1); while(tokens.hasMoreTokens()){ String word = tokens.nextToken(); for (int i = 0; i < word.length(); i++){ switch(word.charAt(i)){ case 'A': case 'a': result+=".-"; break; case 'B': case 'b': result+="-..."; break; case 'C': case 'c': result+="-.-."; break; case 'D': case 'd': result+="-.."; break; case 'E': case 'e': result+="."; break; case 'F': case 'f': result+="..-."; break; case 'G': case 'g': result+="--."; break; case 'H': case 'h': result+="...."; break; case 'I': case 'i': result+=".."; break; case 'J': case 'j': result+=".---"; break; case 'K': case 'k': result+="-.-"; break; case 'L': case 'l': result+=".-.."; break; case 'M': case 'm': result+="--"; break; case 'N': case 'n': result+="-."; break; case 'O': case 'o': result+="---"; break; case 'P': case 'p': result+=".--."; break; case 'Q': case 'q': result+="--.-"; break; case 'R': case 'r': result+=".-."; break; case 'S': case 's': result+="..."; break; case 'T': case 't': result+="-"; break; case 'U': case 'u': result+="..-"; break; case 'V': case 'v': result+="...-"; break; case 'W': case 'w': result+=".--"; break; case 'X': case 'x': result+="-..-"; break; case 'Y': case 'y': result+="-.--"; break; case 'Z': case 'z': result+="--.."; break; case 1 : result+=".----"; break; case 2 : result+="..---"; break; case 3 : result+="...--"; break; case 4 : result+="....-"; break; case 5 : result+="....."; break; case 6 : result+="-...."; break; case 7 : result+="--..."; break; case 8 : result+="---.."; break; case 9 : result+="----."; break; case 0 : result+="-----"; break; } } } return result; } public void mainMethod(){ Scanner input = new Scanner(System.in); boolean DONE = true; while ( s1!equal(DONE)){ System.out.println("Enter line of characters."); String s1 = input.nextLine(); System.out.println("Converted String : " + Conversion(s1)); return false; } } }