Morse code conversion program | Computer Science homework help

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:

  • toMorseCode(char letter) – accepts a single capital letter from the English alphabet and returns an array of 4 characters representing the Morse code equivalent of that letter.
  • fromMorseCode(char[] arr) – accepts an array of four Morse code characters (each either a dot, a dash, or space) and returns the English letter equivalent.

The MorseCode class will have two static variables:

  • char[] alphabet – An array of all 26 letters in the alphabet.
  • char[][] morseCodeAlphabet – an array of arrays of char, storing the morse code entries for all 26 letters of the alphabet.

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

  1. The program should print its name
  2. The program should (continually) ask the user to whether the original phrase will be in English or Morse
  3. For each iteration, the program should ask the user for a phrase (either in English or Morse, depending on the previous choice)
  4. For each iteration, the program will print the result of the conversion (either English to Morse or Morse to English)
    • If the user enters an invalid character, your program should check for an AlphabetException and print an appropriate message.
    • After the error, your program should continue on the next iteration of the main loop (i.e. your program should NOT quit if the user enters an invalid phrase)
  5. Your source code must conform to good programming style, with Javadoc comments on all public methods.

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 = { { "https://www.sweetstudy.com/" }
                            , { '.', '-'           }
                            , { '-', '.', '.', '.' }
                            , { '-', '.', '-', '.' }
                            , { '-', '.', '.'      }
                            , { '.'                }
                            , { '.', '.', '-', '.' }
                            , { '-', '-', '.'      }
                            , { '.', '.', '.', '.' }
                            , { '.', '.'           }
                            , { '.', '-', '-', '-' }
                            , { '-', '.', '-'      }
                            , { '.', '-', '.', '.' }
                            , { '-', '-'           }
                            , { '-', '.'           }
                            , { '-', '-', '-'      }
                            , { '.', '-', '-', '.' }
                            , { '-', '-', '.', '-' }
                            , { '.', '-', '.'      }
                            , { '.', '.', '.'      }
                            , { '-'                }
                            , { '.', '.', '-'      }
                            , { '.', '.', '.', '-' }
                            , { '.', '-', '-'      }
                            , { '-', '.', '.', '-' }
                            , { '-', '.', '-', '-' }
                            , { '-', '-', '.', '.' }
                            };
    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' };

 

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more