Question

Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...

    C++ 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 cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10.   Some of the...

  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 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 cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

  • Please answer with a Java code. Every circle has a center and a radius. Given the...

    Please answer with a Java code. Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design the class Circle that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to capture...

  • Exercise 1: A circle is defined by its radius (we are not interested in its center)....

    Exercise 1: A circle is defined by its radius (we are not interested in its center). A cylinder is defined by circle and height.  Design and implement a class called Circle that has the necessary attributes to describe it and at least the following member methods: setRadius( ), getRadius( ), Circumference( ), Area( ), Display( ), and two constructors, one is parameterized constructor and another empty constructor with default zero value.  Design and implement a class called Cylinder...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The...

    SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

  • I need to implement a program that requests a x,y point and the radius of a...

    I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT