1 package balloonpeople; 2 3 import painter.SPainter; 4 import shapes.SCircle; 5 6 import javax.swing.*; 7 import java.awt.*; 8 import java.util.ArrayList; 9 import java.util.Scanner; 10 11 public class BalloonFamily { 12 static ArrayList<BalloonPerson> balloonPeople = new ArrayList(); 13 static int nrOfPeople; 14 15 public BalloonFamily(int nrOfPeople) { 16 this.nrOfPeople = nrOfPeople; 17 } 18 public void addPeople() { 19 for (int i = 0; i < nrOfPeople; i = i + 1) { 20 String name = JOptionPane.showInputDialog("input name"); 21 String ageStr = JOptionPane.showInputDialog("input age"); 22 int age = Integer.parseInt(ageStr); 23 String heightStr = JOptionPane.showInputDialog("input height"); 24 int height = Integer.parseInt(heightStr); 25 BalloonPerson BP = new BalloonPerson(name, age, height); 26 balloonPeople.add(BP); 27 } 28 } 29 public String toString() { 30 String string = balloonPeople.get(0).toString(); 31 for(int i = 1; i < nrOfPeople-1; i = i + 1) { 32 string = string + " ," + balloonPeople.get(i).toString(); 33 } 34 return string; 35 } 36 37 public void paint(SPainter painter) { 38 39 for(int i = 0; i < nrOfPeople; i = i + 1) { ; 40 int height = balloonPeople.get(i).height; 41 painter.mlt(100); 42 SCircle circle = new SCircle(30); 43 painter.setRandomColor(); 44 circle.setRadius(7); 45 painter.mlt(20); 46 painter.paint(circle); 47 painter.mrt(40); 48 painter.paint(circle); 49 painter.mlt(20); 50 painter.mfd(height/3); 51 circle.setRadius(10); 52 painter.paint(circle); 53 painter.mlt(height/6); 54 painter.paint(circle); 55 painter.mrt(height/3); 56 painter.paint(circle); 57 painter.mlt(height/6); 58 painter.mfd(height/3); 59 circle.setRadius(30); 60 painter.paint(circle); 61 painter.mbk(height/3); 62 painter.mbk(height/3); 63 } 64 } 65 } 66