CS161 Assignment 2: Classes and Objects



The objective of this assignment is to write classes and create objects.
Your task is to convert your code from assignment 1 into an object oriented program by writing your own class called Rectangle. This class will have all the methods that you have written in assignment 1. As in the previous assignment a rectangle is represented by the coordinates of its upper left-hand corner and its bottom right-hand corner (see Assignment 1 for details). It is important to know the definition of a valid rectangle.

Valid rectangle is defined as the one where lower right coordinates are larger than the upper left coordinates. This means if we have a rectangle with the coordinates
(upper_x,upper_y,lower_x,lower_y), then the coordinate, lower_x, should always be greater than the coordinate, upper_x and the coordinate, lower_y, should be greater than the coordinate upper_y.

Coordinates. The coordinates of a valid rectangle should be between 0 and 500. For this assignment this means the lower_x and the lower_y should be less than 500, which is the upper limit of the rectangle size and upper_x and upper_y should not be less than 0.

The Rectangle class that you are supposed to write should have the following methods:


Submitting Your Assignment

Submit your Rectangle.java using the checkin program as PA2.
Note that your code should compile on department Linux machines, and make sure that you are submitting the source code rather than the Java class file.