Question: I need a java code and use eclipse Study the following program TestRectangle.java carefully. Create a class called Rectangle. Rectangle has three double instance variables:
I need a java code and use eclipse
Study the following program TestRectangle.java carefully. Create a class called Rectangle. Rectangle has three double instance variables: height, width and area. When running TestRectangle.jave and Rectangle.java, it will produce the output at the end of this question.
TestRectangle.java:
-
public class TestRectangle {
public static void main(String[] args) {
System.out.println("**********************************");
Rectangle r1 = new Rectangle();
System.out.println("Dimension of R1: " + r1.getWidth() + " X " + r1.getHeight());
System.out.println("Area of R1: " + r1.getArea());
System.out.println("Is R1 a square? " + r1.isSquare());
System.out.println("**********************************");
Rectangle r2 = new Rectangle();
r2.setHeight(2.0);
r2.setWidth(3.0);
System.out.println("Dimension of R2: " + r2.getWidth() + " X " + r2.getHeight());
System.out.println("Area of R2: " + r2.getArea());
System.out.println("Is R2 a square? " + r2.isSquare());
System.out.println("**********************************");
Rectangle r3 = new Rectangle(4.0, 5.0);
System.out.println("Dimension of R3: " + r3.getWidth() + " X " + r3.getHeight());
System.out.println("Area of R3: " + r3.getArea());
System.out.println("Is R3 a square? " + r3.isSquare());
System.out.println("~~ Done! ~~");
}
}
Output:
**********************************
Dimension of R1: 1.0 X 1.0
Area of R1: 1.0
Is R1 a square? true
**********************************
Dimension of R2: 3.0 X 2.0
Area of R2: 6.0
Is R2 a square? false
**********************************
Dimension of R3: 5.0 X 4.0
Area of R3: 20.0
Is R3 a square? false
~~ Done! ~~
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
