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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started