OOP 4 - Geometry
CS20 AP
Main goal of assignment: to work with Multiple Classes, each with multiple Constructors
Create the package OOP4Geometry and the classes you need for this assignment in your Object Oriented Programming (OOP) project.
This package will have 3 files:
- Main class: GeometryMain.java
- Circle class: Circle.java
- Rectangle class: Rectangle.java
Circle Class
- Stores 3 PRIVATE instance variables: name, radius and height (you decide if these should be ints or doubles)
- Has 2 separate constructor methods:
- One accepts a name plus both radius and height. (In other words, you are creating a cylinder).
- One accepts a name for the circle and a radius in METERS. This constructor sets the height to zero. (In other words, you are creating a flat circle, not a cylinder).
- Do not know how to create 2 different constructor methods? It is simple, just create the same method twice but pass in a different set of parameters. In this assignment, one will accept 3 parameters and the other will accept 2.
- Contains 4 additional methods. see below
- public String getName()
- public void printArea()
- this prints the name and the complete surface area of the shape. If it is flat, the surface area is just the 1 side of the circle. If it is a cylinder, it include the rounded side plus the two circular ends.
- use 3.14 for pi
- public void printCircumference()
- this prints the name and the circumference of the circle (or one end of a cylinder)
public void printVolume()
- if height is equal to zero, prints “The _____ (name variable printed) is not a cylinder. Volume can not be computed.”
- else, prints ”The _____ (name variable printed) is a cylinder. It has a volume of ____ cubic metres”. You can calculate and store the volume in a local variable or just calculate it in your print statement.
Rectangle Class
- Stores PRIVATE 4 variables: name, width, length and height (you decide if these should be ints or doubles)
- Has 2 separate constructor methods:
- One accepts name plus width and length. This constructor sets the height to zero.
- One accepts name plus width, length and height. (In this case, you are creating a rectangular prism....think of a computer tower)
- Contains 3 additional methods that should be very similar to the circle versions.
- public String getName()
- public void printArea() - this prints the name and the complete surface area of the shape. If it is flat, the surface area is just the 1 side of the base rectangle. If it is a prism, it includes the four sides plus the two ends. Deep test this formula for accuracy.
- public void printPerimeter() - of the base length and width
- public void printVolume() - shapes with no height should therefore have a volume of zero
Main Class
- Create 2 separate ArrayLists: one for the circles and one for the rectangles. OR jump to the Final 10% section and use single ArrayList to hold both.
- Set up a new Circle. It’s name is Man Hole and it has a radius of 0.5m. It should use the first type of constructor.
- Set up a new Circle. Its name is Tower Of Pisa and it has a radius of 20 m and a height of 80m. It should use the second type of constructor.
- Use a For Loop to print the data for the circles as shown below:
Man Hole has the following properties:
Man Hole’s Area is equal to ___ metres squared.
Man Hole’s Circumference is equal to ___ metres squared.
Man Hole is not a cylinder. Volume can not be computed.
Tower Of Pisa has the following properties:
Tower Of Pisa’s Area is equal to ___ metres squared.
Tower Of Pisa’s Circumference is equal to ___ metres squared.
The Tower of Pisa is a cylinder. It has a volume of ___ cubic metres.
- Set up a new Rectangle called Paper with a width of 0.216m and a length of 0.28m. It should use the first type of constructor.
- Set up a new Rectangle called Printer with a width of 0.36m and a length of 0.32m and a height of 0.24m. It should use the second type of constructor.
- Call and print all methods as before.
Next 10% - Searching
Create a Looping search option so that you can search by the name of the circle or rectangle. If you are using 2 separate ArrayLists, do the two searches separately. If you are going to implement the Final 10% (single ArrayList), you will only have a single search.
What circle do you want to search for?
Tower of Pisa
Tower Of Pisa has the following properties:
…
What rectangle do you want to search for?
Final 10%
- This will require you commenting out some of the above code.
- Instead of using 2 separate ArrayLists, you are going to only create ONE ArrayList where the <objecttype> is not identified. (No angle brackets).
- Then use a single For Loop to print everything regardless of whether it is a Rectangle or Circle
- This will require you to CAST your object into the proper type of object
- That will require you to use instance of in an IF statement.
Evaluation
Circle class: 30%
- Use of constructors
- Use of other methods
Rectangle class: 20% (worth less as it is almost the same as the above)
- Use of constructors
- Use of other methods
Main method 30%
- Creating instances of the Circle and Rectangle classes
- Calling each of the class methods on a particular instance
Searching 10%
Final 10% (using a single list) 10%