Answer:
Step-by-step explanation:
Java Code:
class LandTract {
private int length;
private int width;
public LandTract(int length, int width) {
this.length = length;
this.width = width;
}
public int areaa(){
return length*width;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
@Override
public String toString() {
return "LandTract{" +
"length=" + length +
", width=" + width +
'}';
}
@Override
public boolean equals(Object o)
}
Code Explanation:
Main part of above code is equals method. First check that the passed object in parameter in equals method is equals to current object. If yes then return true.
Otherwise check the class of parameter object is similar to current class. If not then it means the class of parameter object is different so we return false.
Otherwise explicitly convert the object to Our LandTrack class.
Then check both condition where the length and width are equals to length and width, if yes then return true.
Example Main Method
public static void main(String []args){
LandTract landTract1 = new LandTract(21,19);
LandTract landTract2 = new LandTract(19,21);
System.out.println(landTract1.toString());
System.out.println(landTract2.toString());
System.out.println(landTract1.equals(landTract2));
}
Expected Output
LandTract{length=21, width=19}
LandTract{length=19, width=21}
true