CS 12300 - Programming Assignment 2

This assignment is due Wednesday, September 6.

This assignment makes use of the files contained in this zip file.

Write a Java class called Hw2.java which solves Programming Project 3 on page 131 at the end of Chapter 2 of the textbook.

Be sure that the output of your program does not include any leading spaces. So for example, if the input to your program is the following line of text

This    line is spaced    funny

then the output of your program should be like this

Line is spaced    funny This

and not like this

    line is spaced    funny This

Notice how the extra spaces between the words "This" and "line" were dropped from the correct output.

For this assignment you will need to be familiar with Java's String class, which is described in Section 2.2 of the textbook, and Java's Scanner class, which is described in Section 2.3 of the textbook. In particular, be sure to look carefully at Figure 2.5 (page 86) which lists some methods from the String class that you can use for this assignment and at Figure 2.7 (page 98) which lists some methods from the Scanner class.

In this assignment's zip file there are some files that let you test your program. Download and unzip the zip file. Copy your solution file Hw2.java into the unzipped hw2 folder and then compile your Hw2.java file to produce Hw2.class.

Use your keyboard and mouse to "Shift-Right-Click" on an empty space in the hw2 folder and select the pop-up menu item "Open command window here". You should now see a "command prompt" window. Click on this window and type the following command. (Notice that hw2> is the command-line "prompt". You type what comes after the prompt.)

hw2>run_test_script.cmd

That command should produce some output in the command window and the output should look exactly like the contents of the file test_script_output.txt from this assignment's zip file.

Turn in a zip file called CS123Hw2Surname.zip (where Surname is your last name) containing your version of Hw2.java.

This assignment is due Wednesday, September 6.