Question: using these codes make it produce a repeating image using the simpleShapes ( SCircles SPolygons SRectangles and SSquares ) package space; import painter.SPainter; import java.awt.Color;
using these codes make it produce a repeating image using the simpleShapesSCircles SPolygons SRectangles and SSquares
package space;
import painter.SPainter;
import java.awt.Color;
import java.util.Random;
import java.awt.geom.PointD;
import shapes.SRectangle;
public class Droid
private String name;
private static final String CLASS "Astromech Droid"; Example droid class
private int size; Size in arbitrary units
private boolean facingDirection; true for one direction, false for the opposite
private Color color;
Constructor to initialize instance variables
public DroidString name, int size, boolean facingDirection
this.name name;
this.size size;
this.facingDirection facingDirection;
this.color getRandomColor; Initialize with a random color
Method to generate a random color
private Color getRandomColor
Random rand new Random;
return new ColorrandnextInt rand.nextInt rand.nextInt;
Getter methods
public String getName
return name;
public String getClassType
return CLASS;
public int getSize
return size;
public boolean isFacingDirection
return facingDirection;
public Color getColor
return color;
toString method to represent Droid information
@Override
public String toString
return "Droid Name: getName Class: getClassType Size: getSize
Facing Direction: isFacingDirection "Forward" : "Backward"
Color: getColortoString;
Method to check if two Droids could collide
public boolean couldCollideDroid other
return this.facingDirection other.facingDirection; True if facing opposite directions
Method to paint the droid using SPainter
public void paintSPainter painter
painter.setColorcolor;
PointDDouble currentPosition painter.position;
SRectangle rectangle new SRectanglecurrentPositiongetX currentPosition.getY;
painter.paintrectangle;
if facingDirection
painter.dfd size ;
else
painter.dbksize;
package space;
import painter.SPainter;
import javax.swing.SwingUtilities;
public class DroidTester
public DroidTester
Create some Droid instances to test with
Droid droid new DroidRD true;
Droid droid new DroidBB false;
Droid droid new DroidCPO true;
System.out.printlndroid;
System.out.printlndroid;
System.out.printlndroid;
System.out.printlnCollision Test:";
System.out.printlnRD collides with BB droidcouldCollidedroid;
System.out.printlnBB collides with CPO droidcouldCollidedroid;
Assuming SPainter is properly initialized here:
SPainter painter new SPainter;
painter.setVisibletrue; Make sure the painter is visible
droidpaintpainter;
droidpaintpainter;
droidpaintpainter;
public static void mainString args
SwingUtilities.invokeLaternew Runnable
public void run
new DroidTester;
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
