I need to create a method largerThan(See below) which takes a Rectangle object as an argument and returns true if the invoking object has a greater area than the object which is the argument and will return false otherwise. I’ve done this before but simply can’t recall how to complete the code in this part of the method. Any help will be truly appreciated! NOTE: Professor doesn’t want us to use the “this” operator! 🙁
public class Rectangle
{
private double length;
private double width;
public Rectangle()
{
length = 0;
width = 0;
}
public Rectangle(double l, double w)
{
length = l;
width = w;
}
public void setRectangle(double l, double w)
{
length = l;
width = w;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double perimeter()
{
return length + width;
}
public double Area()
{
return length*width;
}
**public boolean largerThan(Rectangle r1)
{
if()
return True;
else
return False;
}**
public String toString()
{
return "Length is " + length + " width is " + width;
}
}
1 Answer