Starting from:
$30

$24

CSc 221: Software Design Laboratory Assignment 3

Please note:

    • This is an individual assignment; please do your own work. Sharing and/or copying code in part or whole with/from others will result in a grade of 0 and disciplinary actions for all involved parties. If you run into problems and have done your best to solve them, please talk to me during office hours or by e-mail.

    • There is a 25% grade deduction for every day the assignment is late unless prior permission is granted.

Preamble

Morse code is a method used in telecommunication to encode text characters as standardized sequences of two different signal durations, called dots and dashes or dits and dahs. Morse code is named for Samuel Morse, an inventor of the telegraph. For further details, I refer to Wikipedia (https://en.wikipedia.org/wiki/Morse_code)

For this assignment, you will write a Java program to convert text (of selected characters) to Morse code using a sequence of dots and dashes. The program consists of the two classes shown in Figure 1. Please note the following:

    • Your code MUST compile and run with the test code provided with the assignment

.. Please do not modify OR submit the test code.

    • Properly comment your code. Comments should precede variables, methods, and major

steps in your code.

    • Follow the Java naming conventions and use the class and method names as shown in the class diagram.

    • File Input: The..class is a multi-purpose class. It can be used to read input from the command line

or from a text file. For instance, the statement

.
creates an instance for reading input from
the

. The statement



creates an instance for reading input from a
text




"file.dat"



file called
file.dat
. After the instance is created, the behavior is the same as with command-line input. Use

to read one







to read one Integer entry …




entry from the command line or the file; use














    • Submit twosource files – do not submit the test class.:

        1. .

        2. .

Running the accompanying JAR:

    1. Create a directory on your file system (e.g. under  3 under)

    2. Place theand both text files in the directory just create.

    3. Open a command prompt console and CD to the directory created in step 1 (e.g./  3)

    4. Typ e the following command: java -jar Assignment3.jar

Note that the path to must be already added to your system’s path, otherwise you must provide the full path to the java executable







Assignment 3 – CSc 221 – CCNY    1

The City College of New York
Department of Compute Science

CSc 221: Software Design Laboratory


Class’ Members:

    I. :

            ▪ Non-default constructor: accepts character values of ASCII codes between 32 and 90 and an encoding value that cannot be NULL and of length at least one. If either criteria is NOT met, the constructor will throw an Exception with the message: ”  ℎ     ℎ               ≪   ℎ     ℎ               ≫   ℎ              ”
            ▪ Setters and Getters: for   ℎ               and.
        II. :

            ▪ listCodes: anto hold objects of type . All valid encodings are held as in this list. Each object in the list represented a single conversion.

            ▪ Non-default constructor:

Accepts one parameter (the file to be read). The constructor attempts to open the file, if it fails, an exception is thrown with the message : ≪ ≫
Read all lines from the file; add each valid line to the . Each line in the input file consists of two columns separated by a tab (i.e. \t). Some lines in the file are corrupt and should be skipped. Make sure to, also, empty lines and lines that do not have exactly two entries. Your program should NOT halt on input errors; read the entire file. If an exception from is encountered, print the exception message, do not add the character to the , and continue to the next line in the input file.
For skipped lines, print the message: ≪   ℎ ≫ and continue with the next line.
            ▪ printEncodingList: Prints the entire content of the.

            ▪ encodeString: Accepts a string parameter and prints the corresponding Morse code for that string.

            ▪ encodeFile:

Accepts a file name as input and prints the corresponding Morse code for the entire file’s content. Attempt to open the file, if it fails, an exception is thrown.

Read the contents of the file and print the corresponding Morse code. If an invalid character is encountered, print ‘?’ for its conversion.
Grading:

Item
Points
Comments (Javadoc and major steps)
10

0


Non-default constructor (char and encoding check)
15
Exception
5
Setters/Getters
10

0


Non-default constructor:
20
Exception

File read

Line skip

Populate list

printEncodingList()
10
encodeString()
10
encodeFile()
20

100



Assignment 3 – CSc 221 – CCNY    2

The City College of New York
Department of Compute Science

CSc 221: Software Design Laboratory


Figures:



















Figure 2: UML Class Diagram
Invalid line: ~

Invalid line: GG

java.lang.Exception: The character \ is not a supported Morse character

java.lang.Exception: The character ^ is not a supported Morse character

java.lang.Exception: The character ` is not a supported Morse character

Select one of the following choices:

    1. Print conversion codes.

    2. Convert string.

    3. Convert file.

    4. Exit.

Choice (1-4):

Figure 3: Program start output messages.
The message ”java.lang.Exception: The character …” is from MorseCode Constructor The message ”Invalid line …” is from MorseCodeConvert Constructor

Select one of the following choices:

    1. Print conversion codes.

    2. Convert string.

    3. Convert file.

    4. Exit.

Choice (1-4): 1

('!', -.-.--)

('"', .-..-.)

('#', -.-..-)

('$', ---..-)

('%', .--..-)

('&', .-...)

(''', .-....)

('(', -.--.)

(')', -.--.-)



Figure 4: Option 1 prints the ArrayList objects

Assignment 3 – CSc 221 – CCNY    3
The City College of New York
Department of Compute Science

CSc 221: Software Design Laboratory

Select one of the following choices:

    1. Print conversion codes.

    2. Convert string.

    3. Convert file.

    4. Exit.

Choice (1-4): 2

Enter line to convert: Hello Java

.... . .-.. .-.. --- .--- .- ...- .-

Figure 5: Option 2 prompts for a line and prints it’s MorseCode equivalence





    i https://en.wikipedia.org/wiki/File:International_Morse_Code.svg











































Assignment 3 – CSc 221 – CCNY    4

More products