Why is not working? Thank you public class LandTract { private double length; pr
ID: 3714358 • Letter: W
Question
Why is not working?
Thank you
public class LandTract
{
private double length;
private double width;
public LandTract(double len, double w)
{
length = len;
width = w;
}
public getArea();
{
return length * width;
}
public boolean equals(LandTract: trac2)
{
boolean status;
// if the second tract length and width are the same as this tract’s length and width, then the two object are equal
if (tract2.length == this.length && tract2.width == this.width)
//this is tract 1
status = true;
else
status = false;
return status;
}
public String toString()
{
String str = “Length = “ + length + “ Width = “ + width + “ Area = “ + getArea();
return str;
}
}
*********
import java.util.Scanner;
public class LandTractDemo
{
public static void main(String[] args)
{
double length, width;
Scanner keyboard = new Scanner(System.in);
System.out.println(“Tract 1”);
System.out.println(“Enter the length of Tract 1”);
length = keyboard.nextDouble();
System.out.println(“Enter the width of Tract 1”);
width = keyboard.nextDouble();
LandTract tract 1 = new LandTract(length, width);
// ———————-Tract 2
System.out.println(“Tract 2”);
System.out.println(“Enter the length of Tract 2”);
length = keyboard.nextDouble();
System.out.println(“Enter the width of Tract 2”);
width = keyboard.nextDouble();
LandTract tract 2 = new LandTract(length, width);
System.out.println(“Tract 1: “ + tract1);
System.out.println(“Tract 2: “ + tract2);
//determine whether the two tracts are equal
if (tract1.equals(tract2))
System.out.println(“ The tracts are the same size”);
else
System.out.println(“ The tracts are NOT the same size”);
}
}
Explanation / Answer
LandTractDemo.java
import java.util.Scanner;
public class LandTractDemo
{
public static void main(String[] args)
{
double length, width;
Scanner keyboard = new Scanner(System.in);
System.out.println("Tract 1");
System.out.println("Enter the length of Tract 1");
length = keyboard.nextDouble();
System.out.println("Enter the width of Tract 1");
width = keyboard.nextDouble();
LandTract tract1 = new LandTract(length, width);
// ———————-Tract 2
System.out.println("Tract 2");
System.out.println("Enter the length of Tract 2");
length = keyboard.nextDouble();
System.out.println("Enter the width of Tract 2");
width = keyboard.nextDouble();
LandTract tract2 = new LandTract(length, width);
System.out.println("Tract 1: " + tract1);
System.out.println("Tract 2: " + tract2);
//determine whether the two tracts are equal
if (tract1.equals(tract2))
System.out.println(" The tracts are the same size");
else
System.out.println(" The tracts are NOT the same size");
}
}
LandTract.java
public class LandTract
{
private double length;
private double width;
public LandTract(double len, double w)
{
length = len;
width = w;
}
public double getArea()
{
return length * width;
}
public boolean equals(LandTract tract2)
{
boolean status;
// if the second tract length and width are the same as this tract’s length and width, then the two object are equal
if (tract2.length == this.length && tract2.width == this.width)
//this is tract 1
status = true;
else
status = false;
return status;
}
public String toString()
{
String str = "Length = " + length + " Width = " + width + " Area = " + getArea();
return str;
}
}
Output:
Tract 1
Enter the length of Tract 1
3
Enter the width of Tract 1
4
Tract 2
Enter the length of Tract 2
5
Enter the width of Tract 2
6
Tract 1: Length = 3.0
Width = 4.0
Area = 12.0
Tract 2: Length = 5.0
Width = 6.0
Area = 30.0
The tracts are NOT the same size
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.