Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify GeometricShape.java to have two more instance data representing the (x,y)

ID: 3909274 • Letter: M

Question

Modify GeometricShape.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 GeometricShape. Create getters and setters for the new values. Modify the type of the color instance data to be Color from the java.awt package.

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.

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. 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. Given a right triangle with two equal sides, we know that ?? 2 + ?? 2 = ?? 2 then ?(2 ? ?? 2) = ?? So we must solve for a.

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.

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.

Exercise 2 Create a new subclass of GeometricShape called Star. Implement the usual members for the class. Create a draw method that draws a 5 sided star at the location given by the x and y instance data. The star should be drawn in the color specified by the color instance data, and if the star should be filled with the color, the draw method should fill the star. Then add a row of stars to the ShapeComponent. The stars should be randomly colored and alternate between being filled and unfilled.

GeometricShape.java:

public abstract class GeometricShape {

//private data members

private String color;

private int Shape;

//constructor

public GeometricShape() {

super();

this.color="white";

}

//getters and setters

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public int Shape() {

return Shape;

}

public void setFilled(int Shape) {

this.Shape = Shape;

}

public static double sumArea(GeometricShape[] shapes) {

    double sum=0;

    for (GeometricShape i:shapes) {

        sum +=i.getArea();

    }

    return sum;

}

public GeometricShape max(GeometricShape s1, GeometricShape s2) {

    if(s1.Shape==s2.Shape) {

        return s1;

    }

    else if(s1.Shape>s2.Shape) {

        return s1;

}

    else return s2;

}

@Override

public String toString() {

return "GeometryShape [color=" + color + ", Shape=" + Shape + "]";

}

abstract int getArea();

abstract int getPerimeter();

}

Explanation / Answer

I have put the requirement for first section here.. As you have not given the class for Circle and Octagon, i am not able to proceed further to give you the solution. Please share them somewhere and then i will take a look. Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote