Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Circle with the following members: Fields: radius , a double variable to store length of radius. PI , a double constant

Create a class called Circle with the following members:

Fields:

radius, a double variable to store length of radius.

PI, a double constant to store value of ?? using Math.PI.

Methods:

Circle, a constructor that gets a double input and assigns it to radius.

setRadius, a set method to assign a value to radius.

getRadius, a get method to return the value of radius.

getPI, a get method to return the value of PI.

circumference, a method that calculates and returns circumference using the following formula:

?? = 2??

area, a method that calculates and returns area using the following formula:

???? = ??2

toString, a method to return a string containing the following information: Name of the shape, radius, circumference, and area.

The Cylinder Class

Create a subclass of Circle called Cylinder and add the following members:

Field:

height, a double variable to store length of height. Methods:Cylinder, a constructor that gets two double inputs and assigns them to radius and height.

Note: In the body of the constructor you should use the following code:

super(radius);

this.height = height;

setHeight, a set method to assign a value to height.

getHeight, a get method to return the value of height. surfaceArea, a method that calculates and returns surface area using the following formula:

?? ????= ?? ???? + 2 ????

volume, a method that calculates and returns volume using the following formula:

= ???? ????

toString, an overridden method to return a string containing the following information: Name of the shape, radius, height, surface area, and volume.

TheConeClass

Create a subclass of Cylinder called Cone and add the following members:

Methods:

Cone, a constructor that gets two double inputs and assigns them to radius and height

Note: In the body of the constructor you should call constructor of Cylinder class using super

keyword.

surfaceArea, an overridden method that calculates and returns surface area using the following formula:

?? ???? = ?? ???? ?????2 + ????2 + ????

volume, an overridden method that calculates and returns volume using the following formula:

= ???? ? 3

Note: You should call volume method of Cylinder class using super.volume() in this method.

toString, an overridden method to return a string containing the following information: Name of the shape, radius, height, surface area, and volume.

Then Create a test class called TestShape. In the main method of this class create one object of Circle class, one object of Cylinder class, and one object of Cone class using their constructors. After creating all objects, use System.out.printf to display their information.

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

02 Identify the organizations safety program needs.

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago