Question: Declare a class called Rectangle with data members length and width, a default constructor that initializes the length and width to zero, a set overloaded
Declare a class called Rectangle with data members length and width, a default constructor that initializes the length and width to zero, a set overloaded constructor that sets the rectangles length and width to valid values, set and get methods for length and width, a method that prints the name and current state of the object called toString(), a method called area() that calculates and returns the area, a method called perimeter() that calculates and returns the perimeter, and an equals() method that returns true if two Rectangle objects have the same state. Then write a test program in a separate file that fully tests the functionality of your class (you must test EACH method). Use the Circle class handout as a guide.
Rectangle UML Diagram
| private int length; private int width; |
| public Rectangle() // default constructor public Rectangle(int l, int w) // overloaded constructor public void setLength(int l) // set methods public void setWidth(int w) public int getLength() // get methods public int getwidth() public int area() // calculate and return area public int perimeter() // calculate and return perimeter public String toString() // print current state of object public boolean equals(Rectangle r) // determine if same state |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
