Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

home / study / engineering / computer science / computer science questions and answers / every cylinder has a base and height, where the base

home / study / engineering / computer science / computer science questions and answers / every cylinder has a base and height, where the base is a circle. design the class cylinder ...

Your question has been answered

Let us know if you got a helpful answer. Rate this answer

Question: Every cylinder has a base and height, where the base is a circle. Design the class cylinder that ...

Every cylinder has a base and height, where the base is a circle. Design the class cylinder that can capture the properties if a cylinder and perform the usual operations on a cylinder. Some of the operations that can be performed on a cylinder are as follows: calculate and print the volume, calculate and print the surface area, set the height, set the radius and base, and set the center of the base. Here is my code so far :

package cylinder;

/**

public class Cylinder {

public static void main(String args[]){

Cylinder cylinder = new Cylinder(3,4);

cylinder.printArea();

cylinder.printVolume();

private double base;

private double height;

public Cylinder(double base, double height) {

this.base = base;

this.height = height;

}

public double getBase() {

return base;

}

public void setBase(double base) {

this.base = base;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getVolume(){

return Math.PI * base*base*height;

}

public void printVolume(){

System.out.println("Volume = " + getVolume());

}

public double getArea(){

return (2*Math.PI*base)*(height+base);

}

public void printArea(){

System.out.println("Area = " + getArea());

}

}

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

Step: 3

blur-text-image

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions