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

Build a \"Diamond\" class to add a diamond shape to the logo created in figure 1

ID: 3572764 • Letter: B

Question

Build a "Diamond" class to add a diamond shape to the logo created in figure 13-12, centered within the circle. Use the following statement after line 11.

myShapes.add(new Diamond(Color.BLACK, 0, 5, 5, 10, 10, 5, 5, 0));

1 Shape .java declares an abstract superclass for shapes. 3 import java.awt.Color; 5 abstract public class shape 6 public shape (color acolor) mycolor acolor 8 public color getColor return mycolor; abstract public void draw (Plotter plot); 10 11 12 private Color mycolor 13 FIGURE 13-5 The shape superclass 1 Circle-java models a circle using its (x,y) center and radius. 3 import java.awt. Color; 5 public class circle extends shape public Circle (Color acolor double centerx, double centerY, double radius) super Cacolor) i myx centerx: myy centerY; my Radius radius; 10 11 12 13 public double getRadius return myRadius; 14 public Point getCenter return new Point (myx, myy) 15 16 public void draw (Plotter plot) double diameter myRadius 2; 17 18 plot.setPencolor super .getcolor plot .drawoval (myx, myY, diameter, diameter) 19 20 21 private double myRadius myx, myY; 23 FIGURE 13-7 Circle.java

Explanation / Answer

/**Diamond.java models a diamond shape based on the (x,y) coordinates of its 4 vertices.

*Mathematically, a diamond is essentially a Rhombus, a 4 sided polygon. The code is as follows

*/

import java.awt.color;

public class diamond extends polygon {

public diamond (color aColor, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4 {

super (aColor, 4);

super.setpoint(0, x1, y1);

super.setpoint(1, x2, y2);

super.setpoint(2, x3, y3);

super.setpoint(3, x4, y4);

}

}

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