Java Must have a LandTract.java and LandTractDemo.java. LandTract Class : Make a
ID: 2246768 • Letter: J
Question
Java
Must have a LandTract.java and LandTractDemo.java.
LandTract Class:
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.
Java
Must have a LandTract.java and LandTractDemo.java.
LandTract Class:
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.
Explanation / Answer
Answer:
Source code:
import java.util.*;
class LandTract{
int length,width;
LandTract(int x,int y){
length=x;
width=y;
}
int tractarea(){
return length*width;
}
int equals(LandTract a,LandTract b){
if(a.tractarea()==a.tractarea())
return 1;
else
return 0;
}
public static void main(String args[]){
Scanner s=new Scanner(System.in);
System.out.println("length and width for tarct 1");
int x1=s.nextInt();
int y1=s.nextInt();
System.out.println("length and width for tarct 2");
int x2=s.nextInt();
int y2=s.nextInt();
LandTract l1=new LandTract(x1,y1);
LandTract l2=new LandTract(x2,y2);
System.out.println("Area of Trat1" +l1.tractarea() + " Area tract 2"+l2.tractarea());
int s1=l2.equals(l1,l2);
if(s1==1)
System.out.println("Equal");
else
System.out.println("not");
}
}
Kindly rate My answer.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.