Question: programs output public class CallRectangle { public static void main(String[] args) { Rectangle myRectangle = new Rectangle(); myRectangle.setSize(1, 1); if (myRectangle.getArea() != 2) { System.out.println(FAILED

programs output

public class CallRectangle { public static void main(String[] args) { Rectangle myRectangle = new Rectangle();

myRectangle.setSize(1, 1); if (myRectangle.getArea() != 2) { System.out.println("FAILED getArea() for 1, 1"); } if (myRectangle.getPerimeter() != 3) { System.out.println("FAILED getPerimeter() for 1, 1"); }

myRectangle.setSize(2, 3); if (myRectangle.getArea() != 8) { System.out.println("FAILED getArea() for 2, 3"); } if (myRectangle.getPerimeter() != 10) { System.out.println("FAILED getPerimeter() for 2, 3"); } } }

public class Rectangle { private int height; private int width;

public void setSize(int heightVal, int widthVal) { height = heightVal; width = widthVal; }

public int getArea() { return height * width; }

public int getPerimeter() { return (height * 2) + (width * 2); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!