BalloonPerson.java
1    package balloonpeople;
2    
3    import java.awt.Color;
4    import java.util.Random;
5    import painter.SPainter;
6    import shapes.SCircle;
7    
8    public class BalloonPerson {
9        //define the instance variables
10       private String name;
11       private int age;
12       private double height;
13       private Color color;
14       private SPainter painter;
15   
16       //define the constructors
17       public BalloonPerson(String name, int age, double height) {
18           this.name = name;
19           this.age = age;
20           this.height = height;
21           this.color = randomColor();
22       }
23       public String toString() {
24           String representation = "(" + "Name: " + name + ", Age: " + age
25                   + ", Height " + height + " inches " + ")";
26           return representation;
27       }
28   
29       private Color randomColor() {
30           Random rgen = new Random();
31           int r = rgen.nextInt(256);
32           int g = rgen.nextInt(256);
33           int b = rgen.nextInt(256);
34           return new Color(r,b,g);
35       }
36   
37       public void paintPerson(SPainter painter) {
38           double spacing = height/4;
39           int headRadius = 30;
40           int bodyRadius = 15;
41           int armRadius = 10;
42           SCircle head = new SCircle(headRadius);
43           SCircle body = new SCircle(bodyRadius);
44           SCircle arm = new SCircle(armRadius);
45           painter.setColor(color);
46   
47           for (int i = 1; i < 4; i = i + 1) {
48               painter.setColor(color);
49               painter.paint(body);
50               painter.mbk(spacing);
51           }
52           painter.mfd(spacing*2);
53           painter.mlt(arm.diameter()*3);
54           for (int i = 1; i < 6; i = i + 1) {
55               painter.mrt(arm.diameter());
56               painter.paint(arm);
57           }
58           painter.mlt(arm.diameter()*2);
59           painter.mfd(headRadius*3);
60           painter.paint(head);
61           painter.mbk(head.diameter());
62   
63   
64       }
65   }
66