Question: CPSC 1181 - Assignment 5 [55 marks] . . Objectives: Create abstract classes Implement interfaces Use interface types to perform polymorphism Please note, Lab 6
![CPSC 1181 - Assignment 5 [55 marks] . . Objectives: Create](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f46816bb383_46266f4681633aa9.jpg)
CPSC 1181 - Assignment 5 [55 marks] . . Objectives: Create abstract classes Implement interfaces Use interface types to perform polymorphism Please note, Lab 6 will be a continuation of this Lab 5. Submission: Zip up all of Java files and submit them to D2L prior to the due date. Unzipped submissions or submissions containing .class files will be automatically given ZERO . Exercise 1 Create an abstract class called Geometric Shape. A Geometric Shape has a color and may or may not be filled with that color. Geometric Shape should contain a default constructor that creates a shape filled with the color white, as well as getters and setters for the two instance data and a toString method. Create two abstract methods: one for getting the area of a shape, and one for getting the perimeter of a shape. Exercise 2 Modify Geometric shape so that it implements the comparable interface. How should shapes be compared? How do you tell if one shape is larger than another? Probably by area. Then create a static method called max that accepts two Geometric Shapes as parameters and returns the larger of the two objects. If the objects are the same size, return the first object that was passed in as a parameter. Exercise 3 Create two child classes of GeometricShape, one called Circle and one called Octagon. Octagon has a side length, Circle has a radius, and each should have an appropriate constructor for initializing instance data. In each class, provide getters and setters for the side length/radius and a toString method. In both of these classes, be sure to implement the abstract methods of the parent class. Exercise 4 Create a static method for finding the total sum of the areas of an array of Geometric Shapes. The method signature is : public static double sumArea (GeometricShape[] shapes) Exercise 5 Create a tester class called Fun WithShapes. Create an Array of Geometric Shapes that contains several Octagons and several Circles. Show that each of the following methods work correctly, for objects of either type: . max . sumArea compareTo (for both Circle and Octagon) Use Arrays.sort to demonstrate that your array of shapes is sorted ascendingly by area CPSC 1181 - Assignment 5 [55 marks] Marking Rubric: Style, Convention, Documentation (8 marks] GeometricShape.java[19 marks] +5 implementing comparable +4 instance data, getters/setters, toString +1 getArea abstract +1 getPerimeter abstract +4 correctly implementing max +3 correctly implementing sumArea Circle.java [9 marks] +1 extends +2 constructor and instance data +2 getter/setter/toString +2 getArea +2 getPerimeter Octagon.java [9 marks) - see Circle.java Fun WithShapes.java[10 marks] +3 checking different cases for Max +3 checking different cases for sumArea +3 checking different cases for compare To +1 showing sort works ascendingly -be sure to compare octagons to circles, circles to circles, and octagons to octagons for thoroughness
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
