1 package balloonpeople; 2 3 import painter.SPainter; 4 5 import javax.swing.*; 6 import java.util.ArrayList; 7 import java.util.Scanner; 8 9 public class BalloonFamily { 10 private ArrayList<BalloonPerson> balloonFamily; 11 12 public BalloonFamily(int nrOfPeople) { 13 this.balloonFamily = new ArrayList<>(); 14 for (int x = 0; x < nrOfPeople; x++) { 15 16 17 String name = getName("Name of Family member"); 18 int age = getAge("Age of Family Member "); 19 int height = getHeight("Height(In Inches) of family Member "); 20 balloonFamily.add(new BalloonPerson(name, age, height)); 21 22 } 23 } 24 25 private String getName(String prompt) { 26 String input = JOptionPane.showInputDialog(null, prompt + "?"); 27 Scanner scanner = new Scanner(input); 28 return scanner.next(); 29 } 30 31 private int getAge(String prompt) { 32 String input = JOptionPane.showInputDialog(null, prompt + "?"); 33 Scanner scanner = new Scanner(input); 34 return scanner.nextInt(); 35 } 36 37 private int getHeight(String prompt) { 38 String input = JOptionPane.showInputDialog(null, prompt + "?"); 39 Scanner scanner = new Scanner(input); 40 return scanner.nextInt(); 41 } 42 43 public String toString(){ 44 int i =0; 45 while(i< balloonFamily.size()){ 46 System.out.println(balloonFamily.get(i)); 47 i++; 48 } 49 return balloonFamily.toString(); 50 } 51 52 public void paint(SPainter painter){ 53 double X = painter.getWidth()/balloonFamily.size(); 54 if ( X < 100) { 55 painter.draw("Error; Too big family picture"); 56 } else { 57 painter.mrt(painter.getWidth()/2); 58 painter.mlt(X/2); 59 balloonFamily.get(0).paint(painter); 60 for (int i = 1; i < balloonFamily.size(); i++) { 61 painter.mlt(X); 62 balloonFamily.get(i).paint(painter); 63 } 64 } 65 } 66 } 67