Question: package geometrytest; import geometryclass.MyPoint; import geometryclass.Rectangle; public class PointRectangleTest { public static void main(String[] args) { double width = 2.71; double height = 8.3; MyPoint
package geometrytest;
import geometryclass.MyPoint; import geometryclass.Rectangle;
public class PointRectangleTest { public static void main(String[] args) {
double width = 2.71; double height = 8.3; MyPoint point2 = new MyPoint(4.1, 9.3); MyPoint point3 = new MyPoint(7.1, 2.3); Rectangle rec6 = new Rectangle(point2, point3); System.out.println("width= " + rec6.getWidth() + " height= " + rec6.getHeight()); System.out.println("area= " + rec6.getArea() + " perimeter= " + rec6.getPerimeter()); } }
package geometryclass;
public class Rectangle { double width = 1; double height = 1; public Rectangle() { } public Rectangle (double newWidth, double newHeight){ width = newWidth; height = newHeight; }
public double getWidth() { return width; } public double getHeight() { return height; } public double getArea() { return width * height; } public double getPerimeter() { return (width + height) * 2; } } }
I am trying to figure out how to pass the object value Rectangle rec6 = new Rectangle(point2, point3); onto the Rectangle class. I can't seem to figure it out after multiple attempts. What should the code be in the Rectangle class in order to print it out in the geometryTest.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
