Question :
Make a LandTract class that has two fields: one for the tract’s length and one for the width. The class should have a method that returns the tract’s area, as well as an equals method and a toString method. Demonstrate the class in a program that asks the user to enter the dimensions for two tracts of land. The program should display the area of each tract of land and indicate whether the tracts are of equal size.
LandTract class
public class LandTract {
private double width,
length;
public LandTract(double width, double length) {
this.width = width;
this.length = length;
}
public double getLength() {
return length;
}
public LandTract(double length) {
this.length = length;
}
public double tractArea(double width, double length) {
return width * length;
}
public String equal(LandTract zt, LandTract lt){
String dec;
if(zt.equals(lt)){
dec ="yes";
}else dec="NO";
return dec;
}
public String toString(){
return "Area is " + width*length;
}
}
DemoTract class
import java.util.Scanner;
public class DemoTract {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please Enter First Tract Width");
double width=scan.nextDouble();
System.out.println("Please Eter First Trach Length ?");
double length=scan.nextDouble();
LandTract lt1 = new LandTract(width,length);
System.out.println("Please Enter Secont Tract Width");
double width2=scan.nextDouble();
System.out.println("Please Enter Secoinf Tract Length");
double length2 = scan.nextDouble();
LandTract lt2 = new LandTract(width2,length2);
System.out.println("First Tract " + lt1);
System.out.println("Secon Tract "+ lt2);
System.out.println(lt2.equal(lt1, lt2));
}
}
object equal is always false, What is wrong with me ?