Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions: write an application that calculates the area of tracts of land as

ID: 3621071 • Letter: I

Question

Instructions: write an application that
calculates the area of tracts of land as well as compares the sizes of the tracts. The user should enter the dimensions of a two tracts of land. The application should display the area of each tract of land and indicate whether the tracts are of equal size.
A LandTract class should be created with 2 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. Two constructors must be coded: one no-arg constructor which sets both instance fields to 1 and one constructor which sets the length and width to the values read from the user. You may take your choice of the constructor that you wish to use from your driver class.
Requirements:
? The application should be named LandArea.java
? An equals method which compares objects must be used to compare the tracts.
A toString method must be used.
? A constructor must be coded in the LandTract class
?needs to be LandArea.java and LandTract.java

Explanation / Answer

public class LandTract implements Comparable<LandTract>
{
/**
* instance variables
*/

private double length, width;

/**
* default constructor: sets length = width = 1
*/

public LandTract()
{
this(1.0, 1.0);
}

/**
* Constructs a LandTract with the given length and width
*/

public LandTract(double l, double w)
{
length = l;
width = w;
}

/**
* @return the area of this LandTract
*/

public double getArea()
{
return length * width;
}

/**
* @return the length of this LandTract
*/

public double getLength()
{
return length;
}

/**
* @return true if dimensions match regardless of orientation
*/

public boolean equals(Object o)
{
LandTract rhs = (LandTract)o;

// rotation is arbitrary, return true if dimensions match
return (length == rhs.length && width == rhs.width) ||
(length == rhs.width && width == rhs.length);
}

/**
* @return the width of this LandTract
*/

public double getWidth()
{
return width;
}

public String toString()
{
return "LandTract: length = "+length+"; width = "+width;
}

/**
* compares two LandTracts: sort by area, descending
*/

public int compareTo(LandTract rhs)
{
if(rhs.getArea() > getArea())
{
return 1;
}
else if(getArea() > rhs.getArea())
{
return -1;
}
else
{
return 0;
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote