Homework 09

Shape Area Program

12/03/2017 at 11:55PM

 

Objective:

 

Write a program where a user populates a collection of various shapes, which is sorted by its area.  The user should be able to specify which type of shape they wish to enter, and then are prompted with the pertinent information which will be used to calculate the shape’s area.    

 

Requirements:

 

The types of shapes the user can enter are:

 

The structure of the program should follow this UML class diagram.

 

 

 

You may also include helper methods that are not noted in the class diagram, but its overall class structure should be what is shown above.

 

Example Output:

 

Welcome to the Shapes collections

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

1

What type of shape?

Rectangle, Triangle, or Circle?

Rectangle

Enter a length followed by a height

3.0 4.0

 

Rectangle Length 3.0 Height 4.0 Area 12.0

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

1

What type of shape?

Rectangle, Triangle, or Circle?

Triangle

Enter a base followed by a height

4.0 5.0

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

1

What type of shape?

Rectangle, Triangle, or Circle?

Circle

Enter a radius

5

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

1

What type of shape?

Rectangle, Triangle, or Circle?

Rectangle

Enter a length followed by a height

-1.0 5.0

Invalid length

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

1

What type of shape?

Rectangle, Triangle, or Circle?

Triangle

Enter a base followed by a height

6.0 7.0

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Triangle Base 6.0 Height 7.0 Area 21.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

2

Enter the shape type

Triangle

Enter an area

21

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

2

Enter the shape type

Circle

Enter an area

10

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

21

Invalid Input

 

Triangle Base 4.0 Height 5.0 Area 10.0

Rectangle Length 3.0 Height 4.0 Area 12.0

Circle  Radius 5.0 Area 78.53981633974483

 

Enter 1: Add a shape

Enter 2: Remove a shape

Enter 9: Quit

9

Good bye

 

Finally:

Upload the .java file to the dropbox