I have a question that I have been searching for an answer to for a while now, both here and in my books. I have found nothing on this issue so far and was wondering if someone can point me in the right direction on where to go with this particular method. I am trying to create a randomShape() method that instantiates and returns a random Shape object. I have all that figured out for the most part my issue is in my support method called getFilledUnfilled(). This support method needs to randomly determine whether a shape is filled/unfilled. Attached below is my code and I will split the method in question up with the rest of the code. Any help would be greatly appreciated. Thank you for your help.
import java.awt.*;
import java.util.*;
public class Shape {
//enumerated constants
public static enum Shapes {OVAL, CIRCLE, RECTANGLE, SQUARE}
//instance data variables
protected Color color;
protected boolean isFilled;
protected int width;
//class method
public static Shape randomShape(){
Shape s = new Shape();
s.getRandomShapeObject();
return s;
}//end randomShape()
//service method (blank, to be overridden by subclasses)
public void draw(Graphics g, int x, int y){
}//end draw()
//support methods
private void getRandomShapeObject(){
ArrayList<Shapes>shapeChoice = new ArrayList<Shapes>();
Random rand = new Random();
int size = shapeChoice.size();
shapeChoice.get(rand.nextInt(size));
}//end getRandomShapeObject()
Here is the method in question
private void getFilledUnfilled(){
ArrayList<Shapes>shapeFillUnfill = new ArrayList<Shapes>();
Random rand = new Random();
}
Thank you all again for your help
Aucun commentaire:
Enregistrer un commentaire