The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
JAVA JAVA for Eclipse
Â
Objective:
The letters of the alphabet A through Z can be represented in Morse code. Each letter is represented by a combination of up to four dots and/or dashes, as shown below. Use Java to write and run a console-window program that can convert an English message into Morse code or a Morse code message into English. The program must satisfy the following requirements:
Description:
Create a class called MorseCode that at least has methods with the following signatures:
The MorseCode class will have two static variables:
Create a class AlphabetException. This class should extend Exception, and be used in case the user enters an invalid character in EITHER mode. For example, if the user wants to convert from English to Morse and enters a lower-case letter, your program should throw an AlphabetException.
Create a driver class called TestMorseCode. At a minimum
Example:
Morse Code Conversion Program.
This program reads a phrase in English(or Morse code) and prints its equivalent in Morse code (or English)
Please select one [1-3]:
1: English -> Morse
2: Morse -> English
3: Quit
1
Enter an English phrase:
PARTY ON
.--. .- .-. - -.-- / --- -.
Please select one [1-3]:
1: English -> Morse
2: Morse -> English
3: Quit
2
Enter a Morse phrase:
.--. .- .-. - -.-- / --- -.
PARTY ON
Please select one [1-3]:
1: English -> Morse
2: Morse -> English
3: Quit
1
Enter an English phrase:
this will cause an error
Letter 't' not in alphabet
Aborting conversion
Please select one [1-3]:
1: English -> Morse
2: Morse -> English
3: Quit
3
Conversion Table:
A .- H .... O --- V ...-
B -... I .. P .--. W .--
C -.-. J .--- Q --.- X -..-
D -.. K -.- R .-. Y -.--
E . L .-.. S ... Z --..
F ..-. M -- T -
G --. N -. U ..-
Â
Â
ADDITIONAL DOC:
 To save time here is the code for the above table
private static char[][]
morseCodeAlphabet = { { '/' }
, { '.', '-' }
, { '-', '.', '.', '.' }
, { '-', '.', '-', '.' }
, { '-', '.', '.' }
, { '.' }
, { '.', '.', '-', '.' }
, { '-', '-', '.' }
, { '.', '.', '.', '.' }
, { '.', '.' }
, { '.', '-', '-', '-' }
, { '-', '.', '-' }
, { '.', '-', '.', '.' }
, { '-', '-' }
, { '-', '.' }
, { '-', '-', '-' }
, { '.', '-', '-', '.' }
, { '-', '-', '.', '-' }
, { '.', '-', '.' }
, { '.', '.', '.' }
, { '-' }
, { '.', '.', '-' }
, { '.', '.', '.', '-' }
, { '.', '-', '-' }
, { '-', '.', '.', '-' }
, { '-', '.', '-', '-' }
, { '-', '-', '.', '.' }
};
private static char[] alphabet = { ' ', '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' };
Â
Â