Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you do this, in java? In keeping with the geometry theme that has been our object-oriented programming experience, you will create an abstract

How do you do this, in java?

In keeping with the geometry theme that has been our object-oriented programming experience, you will create an abstract class named Shape. The class Shape should be defined as follows:

- sides (int) //A variable that holds the number of sides the face of the shape has. You should also have 3 constructors: - a no-arg constructor that initializes the number of sides to 0 - a parameterized constructor that receives an int parameter. The method should call the setSides method - copy constructor You should also define the following methods: - setSides(int) //setter method for the private member - getSides() //getter method for the private member - calcArea() (double) //An abstract method. - toString() //returns a String that gives the number of sides the base shape has.

This Shape class is to be extended by the following classes:

- ThreeDimensional (an abstract class). This class should have a private instance member faces (int), that stores the number of faces of the three dimensional object. Create a no-arg as well as a parameterized constructor. Also define getters and setters for the private member variable and define an abstract method calcVolume() that returns a double value. The class should also have a toString method that lets the user know how many faces the three dimensional object has.

- Rectangle (you may use the one you have already created in previous assignments, with modifications) - Triangle - Circle (you may use the one from previous assignment with modifications)

All these classes should define the method calcArea() based on its own respective geometry. Also, define a toString() method that lets the user know the type of two dimensional shape and the superclass information about how many sides the base shape has.

The following classes should extend the ThreeDimensional class:

- Cylinder - Box - TriPrism Each of these should define surfaceArea() and calcVolume() for the respective geometry. You may chose to use aggregation to help define the Cylinder, Box, and TriPrism classes. Also, define a toString() method that lets the user know the type of three dimensional shape and the superclass information about how many sides the base shape has.

Create a demo class named ShapeDemo that demonstrates the various two dimensional and three dimensional objects. Define an ArrayList of shapes. You are to create 10 Shape objects made up of Rectangle, Circle, Triangle, Cylinder, Box, TriPrism objects. Use an enhanced for loop to display each of the Shape items.

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+What is the most that you should pay to complete development?

Answered: 1 week ago