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

Make a LandTract class with the following fields: • length - an int containing t

ID: 3760306 • Letter: M

Question

Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods : • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if the length of the first is the same as the width of the other and vice versa, that counts as having equal dimensions.) • toString - returns a String with details about the LandTract object in the format: LandTract object with length 30 and width 40 (If, for example, the LandTract object had a length of 30 and a width of 40.) Write a separate program that asks the user to enter the dimensions for the two tracts of land (in the order length of the first, width of the first, length of the second, width of the second). The program should print the output of two tracts' toString methods followed by a sentence stating whether or not the tracts have equal dimensions. (If the tracts have the same dimensions, print, "The two tracts have the same size." Otherwise, print, "The two tracts do not have the same size.") Print all three statements on separate lines. Someone help please this program is killing me. It is chapter 6 Starting out with Java Early Objects 5th Ed. Problem number 71119

Explanation / Answer

CODE :

Class : LandTractMain

import java.util.Scanner;

public class LandTractMain {

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

LandTract obj1=new LandTract();

System.out.println("Enter length on width of 1st Land Tract :");

obj1.length=sc.nextInt();

obj1.width=sc.nextInt();

LandTract obj2=new LandTract();

System.out.println("Enter length on width of 2nd Land Tract :");

obj2.length=sc.nextInt();

obj2.width=sc.nextInt();

System.out.print("Details of 1st LandTract : ");

System.out.print(obj1.toString());

System.out.println();

System.out.print("Details of 2nd LandTract : ");

System.out.print(obj2.toString());

System.out.println();

if(obj1.equals(obj2))

{

System.out.println("The two tracts have same size.");

}

else

System.out.println("The two tracts do not have same size.");

}

}

Class : LandTract

public class LandTract {

public int length;

public int width;

public int area()

{

return length*width;

}

public boolean equals(LandTract obj)

{

if((this.length==obj.length&&this.width==obj.width)||(this.length==obj.width&&this.width==obj.length))

{

return true;

}

else

return false;

}

public String toString()

{

return "The LandTract object had a length of "+this.length+"and a width of "+this.width;

}

}

OUTPUT :

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