Question: // Cylinder class // I NEED INHERITANCE THIS PROGRAM // I NEED HELP PLEASE!!!!!!!!!!! public class Cylinder { private double height; private double radius; public

// Cylinder class

// I NEED INHERITANCE THIS PROGRAM

// I NEED HELP PLEASE!!!!!!!!!!!

public class Cylinder

{

private double height;

private double radius;

public Cylinder(double radius, double height)

{

this.radius = radius;

this.height = height;

}

// Calculate the volume

public double volumeCylinder()

{

double volume = Math.PI * Math.pow(radius,2.0) * height;

return volume;

}

// Calculate the surface

public double SurfaceArea()

{

double diameter = 2 * radius;

double circumference = Math.PI * diameter;

double circleArea = Math.PI * Math.pow(radius,2.0);

double areaCylinder = (2 * circleArea) + (circumference * height);

return areaCylinder;

}

public double Radius()

{

return this.radius; // find radius

}

public double Height()

{

return this.height; // find the height

}

public void Height(double h)

{

this.height = h;

}

public void Radius(double rad)

{

this.radius = rad;

}

// toString method

public String toString()

{

String str = " Radius: " + radius + " " + " Height " + height;

return str;

}

public static void main(String[] args)

{

Cylinder cylinderTest1 = new Cylinder(2, 10);

Cylinder cylinderTest2 = new Cylinder(3, 7);

Cylinder cylinderTest3 = new Cylinder(6, 4);

// Print the dadius and the height

System.out.println(cylinderTest1);

System.out.println(cylinderTest2);

System.out.println(cylinderTest3);

// Display the volumes

System.out.println(" The volume is " +cylinderTest1.volumeCylinder());

System.out.println(" The volume2 is " +cylinderTest2.volumeCylinder());

System.out.println(" The volume3 is " +cylinderTest3.volumeCylinder());

// Display the areas

System.out.println(" The area is " +cylinderTest1.SurfaceArea());

System.out.println(" The area2 is " +cylinderTest2.SurfaceArea());

System.out.println(" The area3 is " +cylinderTest3.SurfaceArea());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!