Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to write a collection of classes to describe the following shapes: Rectangle Square Circle Cylinder Cube Each class should meet the properties defined

I need to write a collection of classes to describe the following shapes:

  • Rectangle
  • Square
  • Circle
  • Cylinder
  • Cube

Each class should meet the properties defined above. In addition, each class should have (either directly or through inheritance):

  • (5 points) variables to describe size, as appropriate for each shape
    • Limiting size variables to only integer values is okay.
  • (5 points) constructor
  • (5 points) getters and setters
    • You can choose not to allow setters. If you allow setters, include validity checks where appropriate.
  • (5 points) a getDescription method that returns the shape properties (described above)
  • (5 points) a toString method that returns the text representation of the simple shape name and size variables
  • (15 points) 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)
  • (15 points) a perimeter, area, and volume method, as appropriate for each shape, as described above

You will also write two additional methods:

  • (5 points) In Cylinder, a method needs to be written 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).
  • (5 points) In Cube, a method needs to be written that takes in a Square and determines if that square could be one side of the current Cube (meaning it has the same size).
  • (10 points) The driver program is missing code. Fill in that missing code. 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. Here's the driver program: (Additionally, I will also provide a link to a zip file with the driver file and the sample output file) Link: https://drive.google.com/file/d/1w9IfaYCaa9fGikDeYxhmHVBLYEZBQuNF/view?usp=sharing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Take as much time as you need, I appreciate your patience and dedication.
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);   Square square3 = 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);   Cylinder cylinder3 = new Cylinder(6, 4);   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(square3);   shapeList.add(circle1);   shapeList.add(circle2);   shapeList.add(cylinder1);   shapeList.add(cylinder2);   shapeList.add(cylinder3);   shapeList.add(cube1);   shapeList.add(cube2);   System.out.println("*****PRINTING OUT THE TEXT REPRESENTATION, DESCRIPTION, AREA, AND PERIMETER/VOLUME OF EACH SHAPE");   for(Shape shape : shapeList) {    System.out.println(shape);    System.out.println(shape.getDescription());    System.out.println("tArea: " + shape.area());       // CODE MISSING: PRINT THE PERIMETER OF TWO-DIMENSIONAL SHAPES    // CODE MISSING: PRINT THE VOLUME OF THREE-DIMENSIONAL SHAPES      System.out.println("");   }   System.out.println(" *****PRINTING ALL EQUAL, NON-ALIAS SHAPES");   for(Shape firstShape : shapeList) {    for(Shape secondShape : shapeList) {     // CODE MISSING: TEST IF THE TWO SHAPES ARE EQUAL (BUT NOT ALIASES!) PRINT THE SHAPES        }   }   System.out.println(" *****PRINTING ALL CUBE/SQUARE COMBINATIONS WHERE THE SQUARE IS A SIDE FOR THE CUBE");   for(Shape firstShape : shapeList) {    for(Shape secondShape : shapeList) {     // CODE MISSING: TEST THE isTopOrBottom METHOD FOR SQUARE/CUBE COMBINATIONS. PRINT ANY MATCHES FOUND.    }   }   System.out.println(" *****PRINTING ALL COMBINATIONS OF TWO-DIMENSIONAL SHAPES THAT CAN FIT INSIDE ANOTHER");   for(Shape firstShape : shapeList) {    for(Shape secondShape : shapeList) {     // EXTRA CREDIT: TEST THE canFitInside METHOD FOR PAIRS OF TWO DIMENSIONAL SHAPES. PRINT ANY SHAPES THAT NEST.    }   }     } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To accomplish the requirements outlined well need to define the classes Rectangle Square Circle Cylinder and Cube each with constructors getterssetters getDescription method toString method equals met... 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

Step: 3

blur-text-image

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

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

=+c) Teachers ranking on their academic class of publications.

Answered: 1 week ago

Question

What are the components of the term performance in the HCI context?

Answered: 1 week ago