Question
Can someone help me check this code? The output didnot show the morse code. And I need the flowchart. Thank you so much! import java.io.*;
Can someone help me check this code? The output didnot show the morse code. And I need the flowchart. Thank you so much!
import java.io.*; import java.util.*; public class Morse { public static int NUM_CHARS = 40; private String original; private String mcode; private char[] regular; private char[] morse;
Morse(String m) { original = m; }
public String toMorse(char ch) { char[] regular = { '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', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',',', '.', '?',' ' };
String[] morse ={ ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".---.", "--.-", ".-.","...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----","..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.","-----", "--..--", ".-.-.-", "..--.."," " }; return " "; }
public String getMorseCode() {
for(int i = 0; i
for (short j = 0; j
if (original.charAt(i) == regular[j]) {
mcode += morse[j];
mcode += " "; } } } return mcode; } public String getOriginal() { return original; } }
import java.util.*;
public class Main { 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()); } }
Morse + NUM CHARS int -40 original : String mcode : String regular : char[] morse : char[ ] + Morse(input: String) + toMorse(ch : char): String + getMorseCode0) : String + getOriginal): StringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started