CSC 211: Program 2

Due: Third Week

Objective of this Program: (1) Using IO inside a program. In particular, how to get input into a program. (2) variable creations and some arithmetic operations. (3) Importing Java API's into a program.

This programming assignment is inspired by Programming Excercise 2.18 on page 111 of the text.

You are to ask the user for data via two types of input: (1) From the console window via the Scanner class and (2) from an input dialog box via the JOptionPane class.

In each case, you ask the user for the width and height of a rectangle, and you tell the user what the area and perimeter of the rectangle is.

You are to tell the user the results in two different places. For the input coming from the console window, the answers should go to the console windows. So, a typical run of the program would look like the following at the console window:

Give the width: 6
Give the height: 8
The area of the rectangle of width 6 and heigth 8 is 48.
The perimeter of the rectangle of width 6 and heigth 8 is 28.

Since the Scanner class is not discussed in the textbook, I have prepared a short note on how to use it here, with an example of using Scanner to see some code using it.

The use of dialog boxes is discussed in your textbook on pages 139-145. I have also provided an example of using input dialog boxes to see some code on using these dialog boxes.

The output dialog box should look something like that given in Figure 3-12 on page 145 of the text.

So to repeat, your program is to do the following:

(i) Ask the user via the Scanner class for the length and width of the
rectangle.
(ii) Print out the area and perimeter of the given rectangle to the console
window.
(iii) Ask the user via the JOptionPane class for the height and width
of another rectangle.
(iv) Print out the area and perimeter of the given rectangle to a dialog box.

In (i) and (iii) above, at least one of them should be using double as input, if not both.

All of the program should be in the main method of your class. There should be no separate submodules called. There should be only one class in your project. There should be not be a separate class for the Scanner and one for the JOptionPane.

For debugging and help on some of the error messages, you should look at An Example of Debugging a Program. This program will also give you some hints on how to do this project.

Note:There is suppose to be only one class for this project. That is to say, there is only one main method and both the Scanner and the JOptionPane class appear in this method.

What to Hand-in

You should post your project as a 'zip' file on the COL website. Also indicate how many hours you worked on the program in the Readme.txt file.


Homepage of CTI School back to 211 homepage