We are going to create 1000 circles in random positions on the screen. Circles closer to the bottom-left corner will be blue and circles closer to the top-right corner will be green. This is an example of return values.

Each circle is 20 pixels by 20 pixels.

Solution

public class CircleRandom2 extends GraphicsProgram {
    private RandomGenerator rd = new RandomGenerator();
    public static final int APPLICATION_WIDTH = 500;
    public static final int APPLICATION_HEIGHT = 500;
    private static final int SIZE = 20;
    
    public void run() {
        for(int i = 0i < 1000i++) {
            int x = rd.nextInt(getWidth()-SIZE);
            int y = rd.nextInt(getHeight()-SIZE);
            GOval o = new GOval(xySIZESIZE);
            o.setFilled(true);
            o.setColor(getColor(xy));
            add(o);
            pause(2);
        }
    }
    private Color getColor(int xint y) {
        if(isGreen(xy)) {
            return Color.green;
        }
        return Color.blue;
    }
    
    private boolean isGreen(int xint y) {
        return x > y;
    }
}
X