Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

JAVA
-
public class CallRectangle {
public static void main(String[] args){
Rectangle myRectangle = new Rectangle();
myRectangle.setSize(1,4);
if (myRectangle.getArea()!=4){
System.out.println("FAILED getArea() for 1,4");
}
if (myRectangle.getPerimeter()!=10){
System.out.println("FAILED getPerimeter() for 1,4");
}
myRectangle.setSize(2,6);
if (myRectangle.getArea()!=12){
System.out.println("FAILED getArea() for 2,6");
}
if (myRectangle.getPerimeter()!=16){
System.out.println("FAILED getPerimeter() for 2,6");
}
}
}
public class Rectangle {
private int height;
private int width;
public void setSize(int heightVal, int widthVal){
height = heightVal -1;
width = widthVal +1;
}
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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago