Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java. project3file: 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

java.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedproject3file:

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. } } }

}

//////output

*****PRINTING OUT THE TEXT REPRESENTATION, DESCRIPTION, AREA, AND PERIMETER/VOLUME OF EACH SHAPE Rectangle Width: 3 Height: 4 Rectangle: A quadrilateral with four right angles Area: 12.0 Perimeter: 14.0

Rectangle Width: 4 Height: 3 Rectangle: A quadrilateral with four right angles Area: 12.0 Perimeter: 14.0

Rectangle Width: 5 Height: 6 Rectangle: A quadrilateral with four right angles Area: 30.0 Perimeter: 22.0

Square Side Length: 2 Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Area: 4.0 Perimeter: 8.0

Square Side Length: 4 Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Area: 16.0 Perimeter: 16.0

Square Side Length: 4 Rectangle: A quadrilateral with four right angles Square: A quadrilateral with four equal sides and four equal angles Area: 16.0 Perimeter: 16.0

Circle Radius: 3 Circle: A closed plane curve every point of which is equidistant from a fixed point within the curve Area: 28.274333882308138 Perimeter: 18.84955592153876

Circle Radius: 5 Circle: A closed plane curve every point of which is equidistant from a fixed point within the curve Area: 78.53981633974483 Perimeter: 31.41592653589793

Cynlinder Radius: 3 Height: 5 Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Area: 150.79644737231007 Volume: 141.3716694115407

Cynlinder Radius: 4 Height: 6 Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Area: 251.32741228718345 Volume: 301.59289474462014

Cynlinder Radius: 6 Height: 4 Cylinder: A solid geometric figure with straight parallel sides and a circular or oval cross section Area: 376.99111843077515 Volume: 452.3893421169302

Cube Side Length: 2 Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Area: 24.0 Volume: 8.0

Cube Side Length: 3 Cube: A three-dimensional solid object bounded by six square faces with three meeting at each vertex Area: 54.0 Volume: 27.0

*****PRINTING ALL EQUAL, NON-ALIAS SHAPES Equal shapes found: Rectangle Width: 3 Height: 4 Rectangle Width: 4 Height: 3 Equal shapes found: Rectangle Width: 4 Height: 3 Rectangle Width: 3 Height: 4 Equal shapes found: Square Side Length: 4 Square Side Length: 4 Equal shapes found: Square Side Length: 4 Square Side Length: 4

*****PRINTING ALL CUBE/SQUARE COMBINATIONS WHERE THE SQUARE IS A SIDE FOR THE CUBE Square-Cube Match Found: Square Side Length: 2 Cube Side Length: 2

*****PRINTING ALL COMBINATIONS OF TWO-DIMENSIONAL SHAPES THAT CAN FIT INSIDE ANOTHER Nested Shapes Found: Outer: Rectangle Width: 3 Height: 4 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Rectangle Width: 4 Height: 3 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Rectangle Width: 3 Height: 4

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Rectangle Width: 4 Height: 3

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Rectangle Width: 5 Height: 6 Inner: Circle Radius: 3

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Rectangle Width: 3 Height: 4

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Rectangle Width: 4 Height: 3

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Rectangle Width: 3 Height: 4

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Rectangle Width: 4 Height: 3

Nested Shapes Found: Outer: Square Side Length: 4 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Circle Radius: 3 Inner: Rectangle Width: 3 Height: 4

Nested Shapes Found: Outer: Circle Radius: 3 Inner: Rectangle Width: 4 Height: 3

Nested Shapes Found: Outer: Circle Radius: 3 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Circle Radius: 3 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Circle Radius: 3 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Rectangle Width: 3 Height: 4

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Rectangle Width: 4 Height: 3

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Rectangle Width: 5 Height: 6

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Square Side Length: 2

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Square Side Length: 4

Nested Shapes Found: Outer: Circle Radius: 5 Inner: Circle Radius: 3

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. o 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. oFor two-dimensional shapes, the area is calculated. o 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): . (5 points) variables to describe size, as appropriate for each shape o Limiting size variables to only integer values is okay. . (5 points) constructor (5 points) getters and setters o 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 oNote 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, 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 (5 points) 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. (10 points) The driver program is missing code. Fill in that missing code. Design Principles (25 points) 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 super whenever possible .Reduce repeated/duplicated code whenever 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. mportant 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. Project Files for Download Project3Files.zip Extra Credit (15 points) -X Write a canFitlnside method that determines if one TwoDimensional shape can fit inside of another. This is true if the parameter of the outer shape are greater than the parameter 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 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. o 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. oFor two-dimensional shapes, the area is calculated. o 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): . (5 points) variables to describe size, as appropriate for each shape o Limiting size variables to only integer values is okay. . (5 points) constructor (5 points) getters and setters o 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 oNote 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, 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 (5 points) 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. (10 points) The driver program is missing code. Fill in that missing code. Design Principles (25 points) 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 super whenever possible .Reduce repeated/duplicated code whenever 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. mportant 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. Project Files for Download Project3Files.zip Extra Credit (15 points) -X Write a canFitlnside method that determines if one TwoDimensional shape can fit inside of another. This is true if the parameter of the outer shape are greater than the parameter 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions