Question: Can I have this in JOptionPane please TY import java.io.*; import java.util.*; class Morse { static int NUM_CHARS = 40; private String original; private String

Can I have this in JOptionPane please TY import java.io.*; import java.util.*; class Morse { static int NUM_CHARS = 40; private String original; private String mcode; private char[] regular; private char[] morse; //Constructs a string original with the given message. Morse(String m) { original = m; } //Takes a character, and converts it into its equivalent morse code. public String toMorse(char ch) { switch(ch) { case ' ': return " "; case ',': return "--..--"; case '.': return ".-.-.-"; case '?': return "..--.."; case '0': return "-----"; case '1': return ".----"; case '2': return "..---"; case '3': return "...--"; case '4': return "....-"; case '5': return "....."; case '6': return "-...."; case '7': return "--..."; case '8': return "---.."; case '9': return "----."; case 'A': return ".-" ; case 'B': return "-..." ; case 'C': return "-.-." ; case 'D': return "-.." ; case 'E': return "." ; case 'F': return "..-." ; case 'G': return "--." ; case 'H': return "...." ; case 'I': return ".." ; case 'J': return ".---" ; case 'K': return "-.-" ; case 'L': return ".-.." ; case 'M': return "--" ; case 'N': return "-." ; case 'O': return "---" ; case 'P': return ".--." ; case 'Q': return "--.-" ; case 'R': return ".-." ; case 'S': return "..." ; case 'T': return "-" ; case 'U': return "..-" ; case 'V': return "...-" ; case 'W': return ".--" ; case 'X': return "-..-" ; case 'Y': return "-.--" ; case 'Z': return "--.." ; } return " "; } //Converts the original string, into its equivalent morsecode, and returns. public String getMorseCode() { mcode = ""; for(int i = 0; i < original.length(); i++) mcode += toMorse(original.charAt(i)); return mcode; } public String getOriginal() { return original; } }
Genarate Morse Main Class import java.util.*; class GenerateMorse { public static void main(String[] args) { System.out.print("Enter the string (To a maximum of 40 characters): "); Scanner sc = new Scanner(System.in); String original = sc.nextLine(); Morse message = new Morse(original); System.out.println("The morse code equivalent of: "+message.getOriginal()+" is: "+message.getMorseCode()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!