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

The software I use is Eclipse, please teach me how to write it on Eclipse. 2. Wr

ID: 3699008 • Letter: T

Question

The software I use is Eclipse, please teach me how to write it on Eclipse.

2. Write a superclass encapsulating a circle; this class has one attribute representing the radius of the circle. It has methods returning the perimeter and the area of the circle. This class has a subclass, encapsulating a cylinder. A cylinder has a circle as its base, and another attribute, its length; it has two methods, calculating and returning its area and volume. You also need to to test these two classes Use the following formula area of the cylinder-2 * ? * radius * radius + 2 * ? * radius * length volume of the cylinder = ? * radius * radius * length

Explanation / Answer

ClientTest.java

public class ClientTest {

public static void main(String[] args) {

Circle c1 = new Circle(2.0);

Cylinder c2 = new Cylinder(3, 2);

System.out.println("Circle area: "+c1.getArea());

System.out.println("Circle perimeter: "+c1.getPerimeter());

System.out.println("Cylinder area: "+c2.getArea());

System.out.println("Cylinder perimeter: "+c2.getPerimeter());

}

}

Circle.java

public class Circle {

private double radius;

public Circle(double radius ){

this.radius = radius;

}

public double getArea() {

return Math.PI * radius * radius;

}

public double getPerimeter(){

return 2 * Math.PI * radius;

}

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

}

Cylinder.java

public class Cylinder extends Circle{

private double length;

public Cylinder(double length, double radius) {

super(radius);

this.length = length;

}

public double getArea() {

return super.getArea();

}

public double perimeter(){

return super.getArea() * length;

}

}

Output:

Circle area: 12.566370614359172
Circle perimeter: 12.566370614359172
Cylinder area: 12.566370614359172
Cylinder perimeter: 12.566370614359172

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote