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

Chapter 10 defined the class circleType to implement the basic properties of a c

ID: 3585063 • Letter: C

Question

Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderTypethat can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleTypedesigned in Chapter 10. 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 of the base, and set the center of the base.

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

  

public double getRadius() {

return radius;

}

public double getArea() {

return Math.PI * radius * radius;

}

public double getCircumference(){

return Math.PI*radius*2;

}

  

public void setOutputCircle(){

System.out.println("Volume of circle: "+getArea());

System.out.println("Circumference of circle: "+getCircumference());

}

}

class Cylinder {

private Circle base;

private double height;

public Cylinder(double r, double h) {

base = new Circle(r);

height = h;

}

public double getVolume() {

return base.getArea() * height;

}

public double getSurfaceArea() {

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

  

}

public void setOutputCylinder(){

System.out.println("Volume of cylinder: "+getVolume());

System.out.println("Surface area of cylinder: "+getSurfaceArea());

}

}

class Ideone

{

public static void main (String[] args) throws java.lang.Exception

{

double radius=5.0;

double height=10.0;

Circle c= new Circle(radius);

c.setOutputCircle();

Cylinder cy = new Cylinder(radius, height);

cy.setOutputCylinder();

}

}

so here is the program in java having the circle as class which has 4 function as getRadius() for getting radius of circel, then getArea() getting area of circel and finally the getcircumference() for getting circumference of circle and setOutputCircle() which prints the area and circumference of circle.

Then the class cylinder and the constructor base has the circle class refrence by using base we can get the functions of class circle which are used to calculate the volume and surface area of cylinder.

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