1). Write a java abstract class called Solid and you will derive two classes – Cylinder and Sphere – from Solid. The class Solid Member variables type whose data type is String. For example, the type could be sphere, cube, parallelepiped. 2). The methods should include: A default or null constructor A constructor that initializes the value of type Getters and Setters An abstract method to find volume whose signature is public abstract double findVolume(); An abstract method to find surface area whose signature is public abstract double findSurfaceArea() a toString method that returns a string like the following Solid Type: Sphere an equals method that returns true if two Solid objects have the same type and false otherwise. 3). The class Cylinder - Cylinder will extend Solid Member variables: Cylinder inherits type from Solid radius of type double height of type double  Methods: a default or null constructor a constructor that initializes type, radius, and height. type will always be “Cylinder”. Remember to pass type to the super class implement the findVolume method. The volume of a cylinder is given by pr 2h where r = radius and h = height implement the findSurfaceArea method. The surface area of a cylinder is 2pr 2 + 2p In Java, p is given by Math.PI a toString method that creates a String like the following. Be sure to use super.toString!! Solid Type : Cylinder Radius : 10 Height 5.1 An equals method that returns true provided super.equals returns true and the two Cylinders have the same height and the two Cylinders have the same radius 4). The class Sphere – Sphere will also extend Solid Member variables radius of type double Sphere inherits type from Solid Method: a default constructor a constructor that initializes type and radius. type will always be “Sphere” Implement findVolume and findSurfaceArea. For a sphere volume = 4.0/3pr 3 surface area = 4pr 2 5). A Test Program: a). Write a method called menu with the signature public static int menu() b). The menu should print all of the choices and ask the user to enter a choice. c). Then menu should declare to read the integer representing the user's choice. This int should be returned to the user. do { choice = menu(); ,,, ,,, } while(choice !=5;   e). In the test program, create an ArrayList of Solid. Write Java code that implements all of the options in the following menu Enter a sphere. Enter a cylinder. Print the toString for all Solids. Print volume and surface area for all solids in the list. QUIT

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1). Write a java abstract class called Solid and you will derive two classes – Cylinder and Sphere – from Solid. The class Solid Member variables type whose data type is String. For example, the type could be sphere, cube, parallelepiped.

2). The methods should include:

  • A default or null constructor
  • A constructor that initializes the value of type
  • Getters and Setters
  • An abstract method to find volume whose signature is public abstract double findVolume();
  • An abstract method to find surface area whose signature is public abstract double findSurfaceArea()
  • a toString method that returns a string like the following Solid Type: Sphere
  • an equals method that returns true if two Solid objects have the same type and false otherwise.

3). The class Cylinder - Cylinder will extend Solid Member variables:

  • Cylinder inherits type from Solid
  • radius of type double
  • height of type double

 Methods:

  • a default or null constructor
  • a constructor that initializes type, radius, and height. type will always be “Cylinder”. Remember to pass type to the super class
  • implement the findVolume method. The volume of a cylinder is given by pr 2h where r = radius and h = height
  • implement the findSurfaceArea method. The surface area of a cylinder is 2pr 2 + 2p In Java, p is given by Math.PI
  • a toString method that creates a String like the following. Be sure to use super.toString!! Solid Type : Cylinder Radius : 10 Height 5.1
  • An equals method that returns true provided
  1. super.equals returns true and
  2. the two Cylinders have the same height and
  3. the two Cylinders have the same radius

4). The class Sphere – Sphere will also extend Solid Member variables

  • radius of type double
  • Sphere inherits type from Solid

Method:

a default constructor

  • a constructor that initializes type and radius. type will always be “Sphere”
  • Implement findVolume and findSurfaceArea. For a sphere
  • volume = 4.0/3pr 3
  • surface area = 4pr 2

5). A Test Program:

a). Write a method called menu with the signature public static int menu()

b). The menu should print all of the choices and ask the user to enter a choice.

c). Then menu should declare to read the integer representing the user's choice. This int should be returned to the user.

do {

choice = menu();

,,,

,,,

} while(choice !=5;

 

e). In the test program, create an ArrayList of Solid. Write Java code that implements all of the options in the following menu

  • Enter a sphere.
  • Enter a cylinder.
  • Print the toString for all Solids.
  • Print volume and surface area for all solids in the list.
  • QUIT

 

 

 

 

 

 

AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education