Ask 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 the tract's area as well as an equals methos and a toString method.

+4
Answers (1)
  1. 28 July, 12:07
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers