Question
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
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 a description that defines the shape.
All shapes have a method that calculates the area.
For two-dimensional shapes, the area is returned.
For three-dimensional shapes, the surface area is returned.
Two-dimensional shapes have a method that returns the perimeter.
Three-dimensional shapes have a method that returns the volume.
Class Design
Think carefully about how to structure the classes. Follow the design principles listed below. You can 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 definition
// a toString method that returns all text definitions that apply to the shape 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 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 but also 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 super whenever possible.
Avoid repeated code.
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). Code that uses these classes will receive a score of 0.
Extra
Write a canFitInside method that determines if one ThreeDimensional shape can fit inside of another (this would be true if the volume of the outer were greater than the volume of the inner). Carefully consider where this method belongs.
Update the driver program to add an additional test to output any nested shapes.
.
.
.
import java.util.*;
public class ShapeTester {
public static void main(String[] args) {
Rectangle rectangle1 = new Rectangle(3,4);
Rectangle rectangle2 = new Rectangle(4,3);
Rectangle rectangle3 = new Rectangle(5,6);
Square square1 = new Square(2);
Square square2 = new Square(4);
Circle circle1 = new Circle(3);
Circle circle2 = new Circle(5);
Cylinder cylinder1 = new Cylinder(3, 5);
Cylinder cylinder2 = new Cylinder(4, 6);
Cube cube1 = new Cube(2);
Cube cube2 = new Cube(3);
List shapeList = new ArrayList<>();
shapeList.add(rectangle1);
shapeList.add(rectangle2);
shapeList.add(rectangle3);
shapeList.add(square1);
shapeList.add(square2);
shapeList.add(circle1);
shapeList.add(circle2);
shapeList.add(cylinder1);
shapeList.add(cylinder2);
shapeList.add(cube1);
shapeList.add(cube2);
for(Shape shape : shapeList) {
System.out.println(shape);
System.out.println("Area: " + shape.area());
// CODE MISSING: PRINT THE PERIMETER OF TWO-DIMENSIONAL SHAPES
// CODE MISSING: PRINT THE VOLUME OF THREE-DIMENSIONAL SHAPES
System.out.println("");
}
for(Shape firstShape : shapeList) {
for(Shape secondShape : shapeList) {
// CODE MISSING: TEST IF THE TWO SHAPES EQUAL (BUT NOT ALIASES!)
// CODE MISSING: TEST THE isTopOrBottom METHOD FOR CYLINDER/CIRCLE COMBINATIONS
// CODE MISSING: TEST THE isASide METHOD FOR CUBE/SQUARE COMBINATIONS
// EXTRA CREDIT: TEST THE canFitInside METHOD FOR PAIRS OF THREE DIMENSIONAL SHAPES
}
}
}
}
OUTPUT:
.
Rectangle: A quadrilateral with four right angles Width: 3 Height: 4 Area: 12.0 Perimeter: 14.0
Rectangle: A quadrilateral with four right angles Width: 4 Height: 3 Area: 12.0 Perimeter: 14.0
Rectangle: A quadrilateral with four right angles Width: 5 Height: 6 Area: 30.0 Perimeter: 22.0
Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Side Length: 2 Area: 4.0 Perimeter: 8.0
Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Side Length: 4 Area: 16.0 Perimeter: 16.0
Circle: A closed plane curve every point of which is equidistant from a fixed point within the curve Radius: 3 Area: 28.274333882308138 Perimeter: 18.84955592153876
Circle: A closed plane curve every point of which is equidistant from a fixed point within the curve Radius: 5 Area: 78.53981633974483 Perimeter: 31.41592653589793
Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 3 Height: 5 Area: 150.79644737231007 Volume: 141.3716694115407
Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 4 Height: 6 Area: 251.32741228718345 Volume: 301.59289474462014
Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 2 Area: 24.0 Volume: 8.0
Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 3 Area: 54.0 Volume: 27.0
Equal Shapes Found: Rectangle: A quadrilateral with four right angles Width: 3 Height: 4 Rectangle: A quadrilateral with four right angles Width: 4 Height: 3
Equal Shapes Found: Rectangle: A quadrilateral with four right angles Width: 4 Height: 3 Rectangle: A quadrilateral with four right angles Width: 3 Height: 4
Matching Shapes Found: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 3 Height: 5 Circle: A closed plane curve every point of which is equidistant from a fixed point within the curve Radius: 3
Nested Shapes Found: Outer: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 3 Height: 5 Inner: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 2
Nested Shapes Found: Outer: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 3 Height: 5 Inner: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 3
Nested Shapes Found: Outer: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 4 Height: 6 Inner: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 3 Height: 5
Nested Shapes Found: Outer: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 4 Height: 6 Inner: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 2
Nested Shapes Found: Outer: Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Radius: 4 Height: 6 Inner: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 3
Matching Shapes Found: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 2 Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Side Length: 2
Nested Shapes Found: Outer: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 3 Inner: Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Side Length: 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started