1 16 17 import java.util.ArrayList ; 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 25 public class Person { 26 private int id; 27 private String category; 28 private String name; 29 private HashMap emails = new HashMap (); 30 private List addresses = new ArrayList (); 31 32 36 public void setId(int id) { 37 this.id = id; 38 } 39 40 public void setCategory(String category) { 41 this.category = category; 42 } 43 44 public void setName(String name) { 45 this.name = name; 46 } 47 48 49 public void addEmail(String type, String address) { 50 emails.put(type, address); 51 } 52 53 public void addAddress( Address addr ) { 54 addresses.add( addr ); 55 } 56 57 public void print() { 58 System.out.println("Person #" + id); 59 System.out.println(" category=" + category); 60 System.out.println(" name=" + name); 61 62 for(Iterator i = emails.keySet().iterator(); i.hasNext(); ) { 63 String type = (String ) i.next(); 64 String address = (String ) emails.get(type); 65 66 System.out.println(" email (type " + type + ") : " + address); 67 } 68 69 for(Iterator i = addresses.iterator(); i.hasNext(); ) { 70 Address addr = (Address) i.next(); 71 addr.print(System.out, 2); 72 } 73 } 74 } 75 | Popular Tags |