Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have: a constructor that accepts arguments for the two fields a method that returns the tract’s area(i.e. length * width) an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and width) as the calling object, this method should return true. Otherwise, it should return false. a toString method (that returns a String representation of the tract’s length, width, and area). Demonstrate the class in a program by creating an array of three LandTract objects initialized with user input. Then, print the info of the LandTract objects stored in the array by invoking the toString method (implicitly or explicity). Also, use the equals method to compare at least two LandTract objects and print wether they are of equal size or not. Sample Output: Enter the length of Tract 1: 2 Enter the length of Tract 1: 3 Enter the length of Tract 2: 2 Enter the length of Tract 2: 3 Enter the length of Tract 3: 4 Enter the length of Tract 3: 5 Info of LandTract 1: Length = 2.0 Width = 3.0 Area = 6.0 Info of LandTract 2: Length = 2.0 Width = 3.0 Area = 6.0 Info of LandTract 3: Length = 4.0 Width = 5.0 Area = 20.0 The first and second tracts are the same size. Use Java
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:
a constructor that accepts arguments for the two fields
a method that returns the tract’s area(i.e. length * width)
an equals method that accepts a LandTract object as an argument. If the argument object
holds the same data (i.e. length and width) as the calling object, this method should return
true. Otherwise, it should return false.
a toString method (that returns a String representation of the tract’s length, width, and
area).
Demonstrate the class in a program by creating an array of three LandTract objects initialized with user input. Then, print the info of the LandTract objects stored in the array by invoking the toString method (implicitly or explicity). Also, use the equals method to compare at least two LandTract objects and print wether they are of equal size or not.
Sample Output:
Enter the length of Tract 1: 2
Enter the length of Tract 1: 3
Enter the length of Tract 2: 2
Enter the length of Tract 2: 3
Enter the length of Tract 3: 4
Enter the length of Tract 3: 5
Info of LandTract 1:
Length = 2.0
Width = 3.0
Area = 6.0
Info of LandTract 2:
Length = 2.0
Width = 3.0
Area = 6.0
Info of LandTract 3:
Length = 4.0
Width = 5.0
Area = 20.0
The first and second tracts are the same size.
Use Java
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images