import java.util.Random; import java.awt.Color; public class RandomShapes { public static Drawable[] makeShapes() { Random rand = new Random(); Drawable[] list = new Drawable[rand.nextInt(20)]; for (int i = 0; i < list.length; i++) { list[i] = makeRandomShape(rand); } return list; } public static Drawable makeRandomShape(Random rand) { int shapeIndex = rand.nextInt(3); if (shapeIndex == 0) { return new Rectangle(new Point(rand.nextInt(400), rand.nextInt(400)), new Point(rand.nextInt(400), rand.nextInt(400)), rand.nextInt(10) + 1, Color.RED); } else if (shapeIndex == 1) { Point[] list = new Point[rand.nextInt(5)+1]; for (int i = 0; i < list.length; i++) { list[i] = new Point(rand.nextInt(400), rand.nextInt(400)); } return new Polygon(list, rand.nextInt(10) + 1, Color.BLUE); } else { return new SolidPoint(rand.nextInt(400), rand.nextInt(400), Color.BLACK); } } }