215k views
2 votes
Make a ladtract class that has 2 fields, one for the tractor's length and one for the width. The class should have a method that returns the tract's area as well as an equals methos and a toString method.

User Arbylee
by
5.7k points

1 Answer

4 votes

Step-by-step explanation:

Below is the java code for the ladtract class :-

public class ladtract

{

private double length; //length of tractor

private double width; //width of tractor

public double calculateArea(){

return length*width; //calculate and return the area of the tractor

}

public boolean equals(Object o) {

if (o == this) { //check if it's the same object

return true;

}

if(o.length==this.length && o.width==this.width){ //check if the length and width are same for both objects

return true;

}

return false;

}

public String toString(){

return "Area="+calculateArea(); //return the area of the tractor as a string

}

}

User Rezigned
by
5.3k points