我正在尝试创建一个randomShape()方法,该方法实例化并返回一个随机的Shape对象。我已经解决了大部分问题,我的问题是在我的支持方法getFilledUnfilled()中。该支撑方法需要随机确定形状是否填充/未填充。以下是我的代码。
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()
以下是问题的方法
private void getFilledUnfilled(){
ArrayList<Shapes>shapeFillUnfill = new ArrayList<Shapes>();
Random rand = new Random();
}