Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. Objectives: Create abstract classes Implement interfaces Use interface types to perform polymorphism Please note, Lab 6 will be a continuation of this Lab 5.

image text in transcribed

image text in transcribed

image text in transcribed

. 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 Geometric Shape, 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 With Shapes. 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 compare To (for both Circle and Octagon) Use Arrays.sort to demonstrate that your array of shapes is sorted ascendingly by area . . Objectives: Design drawing methods for shapes Design Components and Frames in Graphical Applications Describe the importance of code refactoring This is a continuation of Assignment 5. Assignment 7 will be a partial continuation of Assignment 6 (it will use your Geometric Shape, Arrow, Circle, and Octagon classes from this lab). 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 Modify Geometric Shape.java to have two more instance data representing the (x,y) location the shape is drawn at. Create a constructor that sets all four properties of the Geometric Shape. Create getters and setters for the new values. Modify the type of the color instance data to be Color from the java.awt package. Exercise 2 Modify the constructors of Circle and Octagon to accept values for X and Y, and change the type of the color parameter to be Color. Exercise 3 Create the method public void draw(Graphic2D g2) in Circle and Octagon. This method should draw the shape at the location given by the instance data x and y. The shape should be drawn in the color specified by the color instance data, and if the shape should be filled with the color, the draw method should fill the shape. Hint: We know one point on our Octagon, the x and y that are passed as parameters, as well as the side length d. d a We can use Pythagoras to find out the length a, which will allow us to figure out all the points on our octagon using addition and subtraction. a Given a right triangle with two equal sides, we know that a + a? = d? then 2 * a2 = d? So we must solve for a. Bonus Hint: I suggest picking the red point as (x,y). Then moving one point to the right would make the next point (x + a, y), and so on and so forth. Exercise 4 Create a class called ShowShapes with a main method. In the main method create a Frame that is 500 by 500. Set the usual properties of the frame. Exercise 5 Create a ShapeComponent class that extends JComponent. Create the paintComponent method and make it draw a row of Octagons that alternate between being filled and being empty. Then draw a row of colored circles that alternate between being filled and being empty. Add a shapeComponent to the frame created in the previous exercise. A screenshot of the completed application is shown at the bottom of the page. Exercise 6 Create a new subclass of Geometric Shape called Arrow. An arrow is an equilateral triangle attached to the right side of a square. The side length of the square should be stored as a piece of instance data for the Arrow. Make the side length of the equilateral triangle three times that of the square. There is no need to store the triangle side length as instance data. Implement the usual members for the class, including the inherited abstract methods. Create a draw method that draws an Arrow at the location given by the x and y instance data. The Arrow should be drawn in the color specified by the color instance data, and if the Arrow should be filled with the color, the draw method should fill the Arrow. Then add a row of Arrows to the ShapeComponent. The Arrows should be randomly colored and alternate between being filled and unfilled. Marking Rubric: Style, Convention, Documentation (5 marks] Modifications to Geometric Shape [5 marks] Octagon.java [10 marks) +3 updating instance data +7 correctly implementing draw Arrow.java [12 marks] +7 correct members and inheritance +5 correctly implementing draw ShapeComponent.java[10 marks] +1 extends +3 row of Octagons +3 row of Circles +3 row of Arrows ShowShapes.java[6 marks] +5 setting properties of Frame +1 adding shapeComponent Circle.java [6 marks] +3 updating instance data +3 correctly implementing draw Bonus: +3 for making all the shapes truly random colors Showing Shapes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions