AlternateBalloons.java
1    /* 
2     * Program that prints 300 red, yellow, orange, green, blue and pink balloons in a blue sky. 
3     * It will feature commands 
4     */
5    
6    package npw;
7    
8    import java.awt.Color;
9    import java.util.Random;
10   import javax.swing.SwingUtilities;
11   import painter.SPainter;
12   import shapes.SCircle;
13   import shapes.SSquare;
14   
15   public class AlternateBalloons {
16   
17       // REQUIRED INFRASTRUCTURE
18   
19       public AlternateBalloons() {
20           paintTheImage();
21       }
22   
23       public static void main(String[] args) {
24           SwingUtilities.invokeLater(new Runnable() {
25               public void run() {
26                   new AlternateBalloons();
27               }
28           });
29       }
30   
31       // THE PAINTER DOING ITS THING
32   
33       private void paintTheImage(){
34           SPainter painter = new SPainter("Balloons", 600,600);
35           paintSky(painter);
36           int nrOfBalloons = 300;
37           paintBalloons(painter, nrOfBalloons);
38       }
39   
40       private void paintSky(SPainter painter) {
41           painter.setColor(Color.BLUE);
42           SSquare sky = new SSquare(2000);
43           painter.paint(sky);
44       }
45   
46       private void paintBalloons(SPainter painter, int nrOfBalloons) {
47           int i = 1;
48           while (i <= nrOfBalloons){
49               paintOneBalloon(painter);
50               i = i + 1;
51           }
52       }
53   
54       private void paintOneBalloon(SPainter painter) {
55           Random rgen = new Random();
56           int rn = rgen.nextInt(6);
57           if(rn == 0){
58               painter.setColor(Color.RED);
59           }else if(rn == 1){
60               painter.setColor(Color.ORANGE);
61           }else if(rn == 2){
62               painter.setColor(Color.YELLOW);
63           }else if(rn == 3){
64               painter.setColor(Color.GREEN);
65           }else if(rn == 4){
66               painter.setColor(Color.BLUE);
67           }else{
68               painter.setColor(Color.PINK);
69           }
70           painter.move();
71           int balloonRadius = 30;
72           SCircle balloon = new SCircle(balloonRadius);
73           painter.paint(balloon);
74           painter.setColor(Color.BLACK);
75           painter.draw(balloon);
76       }
77   
78   }