Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

What costs should be covered by the selling price of a new product?

Answered: 1 week ago

Question

What effect does altering the bandwidth have on the above?

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago