Question: java Write a Rectangle class to hold the length and the width. Write the obvious constructor. Write the toString () method for the class. Revise
java
Write a Rectangleclass to hold the length and the width.
Write the obvious constructor.
Write the toString()method for the class.
Revise your constructor above such that it has the ability to detect which input is the length and which one is the width. You will need to use the ifstatement here.
Suppose there is no ifstatement in the language, how can you implement the above question? (Hint: think of Math.minand Math.max).
Write a constructor that takes two points as parameters. Create a Pointclass to assist you. Do not store these points. What must be stored is the lengths of the two sides, just as before.
Write a method to compute the perimeter of the rectangle.
Write a method to compute the area of the rectangle.
Write a method that returns a new Rectangle that is as double as the original one. Do not change the existing object.
Write a new class called TestRectangle, which contains the main method in order to test your classes. In the main method do the following tasks:
1.Create two rectangle objects
2.Create twopoint objects
3.Create a third rectangle using the above two points.
4.Print out the perimeter and the area of the rectangle objects.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
