Write a collection of classes to describe the following shapes:
Rectangle
Square
Circle
Cylinder
Cube
Shape Characteristics
The shapes have the following characteristics:
All shapes have dimensions that describe their size.
All shapes have a method that returns a text description that lists all properties of all names that describe the shape.
Example: A square description might be: Rectangle (a quadrilateral with four right angles) and Square (a quadrilateral with four equal sides and four equal angles)
All shapes have a method that calculates the area.
For two-dimensional shapes, the area is calculated.
For three-dimensional shapes, the surface area is calculated.
Two-dimensional shapes have a method that calculates the perimeter.
Three-dimensional shapes have a method that calculates the volume.
Class Design
Think carefully about how to structure the classes. Follow the design principles listed below. You can (and should!) create an additional parent class and interfaces, as needed.
Each class should meet the properties defined above. In addition, each class should have (either directly or through inheritance):
variables to describe size, as appropriate for each shape
Limiting size variables to only integer values is okay.
constructor
getters and setters
You can choose not to allow setters. If you allow setters, include validity checks where appropriate.
a getDescription method that returns the shape properties (described above)
a toString method that returns the text representation of the simple shape name and size variables
an equals method: two shapes are the same if they have the same description and the same size
Note that for the Rectangle class, the rectangle (3,4) should be considered the same as the rectangle (4,3)
a perimeter, area, and volume method, as appropriate for each shape, as described above
You will also write two additional methods:
In Cylinder, write a method that takes in a Circle and determines if that circle could be a top/bottom of the current cylinder (meaning it has the same size).
In Cube, write a method that takes in a Square and determines if that square could be one side of the current Cube (meaning it has the same size).
I have provided a driver program and the sample output you should obtain when you run the program.
The driver program is missing code. Fill in that missing code.
Design Principles
You will be graded both on your syntax and your class design. For full credit, follow good principles of programming, object-oriented design, and inheritance. Also consider these design elements:
For all required methods, your class can either include the method directly or inherit it. Think about where the method logically belongs.
Think about what the parent-child relationship should be between the classes.
Think about what classes should be abstract.
Think about what interfaces you should create.
Move common code as high up in the hierarchy as possible.
Use constants for hard-coded numeric and text values.
Follow appropriate naming and style conventions.
Follow good principals of object-oriented design and inheritance.
Important Note
Do not use any of the Shape classes in the Java Standard Library (either in the awt packages or the FX packages).
Extra Credit
Write a perimeterCanFitInside method that determines if one TwoDimensional shape can fit inside of another based only on perimeter. This is true if the perimeter of the outer shape is greater than the perimeter of the inner shape.
Carefully consider where this method belongs.
Update the driver program to add an additional test to output any nested two-dimensional shapes.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.