Question: This is a JAVA problem. In this assignment you are going to create a Rectangle class to perform certain operations that are relevant to rectangles.
This is a JAVA problem.
In this assignment you are going to create a Rectangle class to perform certain operations that are relevant to rectangles. Also, you will create a RectangleTest class to demonstrate its functionality.
Rectangle class should have length and width parameters to account for two sides. Area is not an instance variable; it is something that can be calculated once the user calls getArea().
The methods you should have:
- Rectangle() //default constructor that sets 0 to both length and width
- Rectangle(int, int) //constructor that initializes both variables.
- toString() //returns a string to display rectangle information
- isSquare() //method to check if length equals width. If it is, returns true.
You should create 3 rectangles in your system. Then use toString method to display the rectangle information.
A sample code block in the main should look something like (for 1 rectangle):
Rectangle r1 = new Rectangle(10,10); System.out.println(r1); //dont forget, this call means return the string coming from r1.toString().
And this should display something like***:
A new object defined. Length: 10 Width: 10 This object is a square.
***So arrange your toString() method accordingly
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
