Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

How can debug this program? Can you help me to check my code? public class Rectangle { private int lenght; private int width; public Rectangle(int

How can debug this program? Can you help me to check my code?

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

public Rectangle(int length) { this.length = length; } public int getLength() { return length; } public Rectangle(int width) { this.width = width; } public int getWidth() { return width; } public Rectangle(int area) { this.area = area; } public int getArea() { return length*width; } public boolean equals (Rectangle r1, Rectangle r2) { if (r1.getArea() == r2.getArea()) return true; else return false; } }

public class CompareUsingequalsMethod { public static void main(String[] args) {

Rectangle r1 = new Rectangle(3, 5); Rectangle r2 = new Rectangle(4, 4);

if (r1.equals(r1,r2)) { System.out.println("Rectangle1 with area " + r1.getArea() + " is equal to Rectangle2 with " + "area " + r2.getArea()); } else { System.out.println("Rectangle1 with area " + r1.getArea() + " is not equal to Rectangle2 with " + "area " + r2.getArea()); }

}

}

} image text in transcribed

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