Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given this code: public class Rectangle implements Comparable{ public final int NUM_OF_SIDES = 4; private double length; private double width; public Rectangle(){ length = 2;

Given this code:

public class Rectangle implements Comparable{ public final int NUM_OF_SIDES = 4; private double length; private double width; public Rectangle(){ length = 2; width = 2; } public Rectangle(double l, double w){ length = l; width = w; } public void setLength(double l){ length=l; } public void setWidth(double w){ width = w; } public double getLength(){ return length; } public double getWidth(){ return width; } public double getPerimeter(){ return 2*length + 2*width; } public double getArea(){ return length * width; } public boolean equals(Object obj){ if(obj instanceof Rectangle){ Rectangle that = (Rectangle) obj; if(this.length == that.length && this.width == that.width){ return true; } } return false; } public int compareTo(Object obj){ if(obj instanceof Rectangle){ Rectangle that = (Rectangle) obj; double diff = this.getArea() - that.getArea(); if(Math.abs(diff) <=.001){ return 0; } else if (diff > 0){ return 1; } else { return -1; } } return 1; } public String toString(){ return "Rectangle: " +"\tlength:\t" + length + " " +"\twidth:\t" + width + " "; } }

answer this:

What value is stored in this variable result:

1)

Rectangle r = new Rectangle(2, 4);

double result = r.getPerimeter()*r.getArea()%r.NUM_OF_SIDES;

2)

Rectangle r = new Rectangle(3,3);

double result = 2;

if(r.equals(r.toString())){

result -= 5;

}else{

result *= 2;

}

result += r.getArea(2);

(if you can please explain how you got answer, thanks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago