Homework 2
CS202, Summer 2006

Due: Tuesday, July 18

Please upload your source code files using CSNS. Note that file uploading will be disabled automatically after 11:59PM of the due date, so please turn in your work on time.


1. Write a Point class which has two private double fields x and y, which correspond to the x and y coordinates of a point. Include the following methods in the class:

2. Re-use your Point class and write a new class Rectangle. Rectangle has two Point fields, lowerLeft and upperRight, which correspond to the two corner points of a rectangle. Include the following methods in the class:

3. (10pt) Write a GeometryTest class which only has a main method. Inside the main method, create a few Point and Rectangle objects, and properly test all methods of these two classes, including all the constructors.

4. (20pt) [Textbook] 29.21

5. (+30pt) [Textbook] 29.22

HINT: to avoid long switch statement, you may consider using arrays. For example, create an array

String ones[] = { "", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN" }

then the string representation of a single digit number n is simply ones[n].