Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write your answer in the space provided. 11) Write the definition for a child cl

ID: 3737389 • Letter: W

Question

Write your answer in the space provided. 11) Write the definition for a child class of Circle named Cylinder. The cylinder should have a double attribute named height. The constructor of the child class should take parameters to initialize the attributes. The class Cylinder should also include getter and setter method as well as an equals method that returns true if two cylinder objects have same dimensions and false otherwise. Remember to override method where needed. public class Circle protected double radius; public Circle (double r) radius r public void setRadius (double r) radius r public double getRadius) ( return radius public double area) return Math.PI radius * radius; public String tostring) return "Circle:Radius radius; I

Explanation / Answer

Cylinder.java

public class Cylinder extends Circle{

private double height;

public Cylinder(double r, double h) {

super(r);

height = h;

}

public void setHeight(double h) {

height = h;

}

public double getHeight() {

return height;

}

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Cylinder other = (Cylinder) obj;

if (Double.doubleToLongBits(height) != Double

.doubleToLongBits(other.height))

return false;

return true;

}

}