Question: Hello....so far... I wrote the code but it's giving me an error import java.io.*; import java.util.*; public class Morse { static int NUM_CHARS = 40;

Hello....so far... I wrote the code but it's giving me an error
import java.io.*; import java.util.*;
public 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. */ public Morse(String m) { original = m; } //Takes a character, and converts it into its equivalent morse code. public String toMorse(char code) { String ch = ""; switch(code) { case ' ': ch = " "; break; case ',': ch = "--..--"; break; case '.': ch = ".-.-.-"; break; case '?': ch = "..--.."; break; case '0': ch = "-----"; break; case '1': ch = ".----"; break; case '2': ch ="..---"; break; case '3': ch = "...--"; break; case '4': ch = "....-"; break; case '5': ch ="....."; break; case '6': ch = "-...."; break; case '7': ch ="--..."; break; case '8': ch = "---.."; break; case '9': ch ="----."; break; case 'A': ch = ".-" ; break; case 'B': ch = "-..." ; break; case 'C': ch = "-.-." ; break; case 'D': ch ="-.." ; break; case 'E': ch = "." ; break; case 'F': ch = "..-." ; break; case 'G': ch ="--." ; break; case 'H': ch = "...." ; break; case 'I': ch = ".." ; break; case 'J': ch = ".---" ; break; case 'K': ch = "-.-" ; break; case 'L': ch = ".-.." ; break; case 'M': ch = "--" ; break; case 'N': ch = "-." ; break; case 'O': ch = "---" ; break; case 'P': ch = ".--." ; break; case 'Q': ch = "--.-" ; break; case 'R': ch = ".-." ; break; case 'S': ch = "..." ; break; case 'T': ch ="-" ; break; case 'U': ch = "..-" ; break; case 'V': ch = "...-" ; break; case 'W': ch = ".--" ; break; case 'X': ch = "-..-" ; break; case 'Y': ch = "-.--" ; break; case 'Z': ch = "--.." ; break; } return ch; }
//Converts the original string, into its equivalent morsecode, and returns. public String getMorseCode(char upper, String code) { mcode = ""; for(int i = 0; i
public String getOriginal() { return original; }
}
import java.io.*; import java.util.Scanner;
public class MorseDemo { public static void main(String[] args) { System.out.print("Enter the string (To a maximum of 40 characters): "); Scanner keyboard = new Scanner(System.in); String original = keyboard.nextLine(); Morse message = new Morse(original); System.out.println("The morse code equivalent of:" +message.getOriginal()+ " is:" +message.getMorseCode()); }
17. Morse Code Converter Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes. Table 10-8 shows part of the code. Write a program that asks the user to enter a string, and then converts that string to Morse code. Table 10-8 Morse Code Character Code Character Code Character Code Character Code space space comma.. period question mark
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
