Ask Question
4 March, 23:45

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.

+3
Answers (1)
  1. 5 March, 03:09
    0
    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

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers