/Users/lyon/j4p/src/addBk/address/AddressRecord.java

1    package addBk.address; 
2     
3    import java.io.Serializable; 
4     
5    public class AddressRecord 
6            implements Serializable, 
7            Comparator { 
8        private String firstName; 
9        private String lastName; 
10       private String address1; 
11       private String address2; 
12       private String phone1; 
13       private String phone2; 
14       private String phone3; 
15    
16       public String[] getRecordAsArray() { 
17           String defaultRecord[] = 
18                   {firstName, 
19                    lastName, 
20                    address1, 
21                    address2, 
22                    phone1, 
23                    phone2, 
24                    phone3}; 
25           return defaultRecord; 
26       } 
27    
28       public String getPhone1() { 
29           return phone1; 
30       } 
31    
32       public String getPhone2() { 
33           return phone2; 
34       } 
35    
36       public String getPhone3() { 
37           return phone3; 
38       } 
39    
40       public String getLastName() { 
41           return lastName; 
42       } 
43    
44       public int compare(Object o1, Object o2) { 
45           AddressRecord a1 = (AddressRecord) o1; 
46           AddressRecord a2 = (AddressRecord) o2; 
47           String n1 = a1.getLastName(); 
48           String n2 = a2.getLastName(); 
49           return n1.compareTo(n2); 
50       } 
51    
52       public boolean equals(Object obj) { 
53           AddressRecord a = 
54                   (AddressRecord) obj; 
55           return lastName.equals(a.getLastName()); 
56       } 
57    
58       public String getAddress1() { 
59           return address1; 
60       } 
61    
62       public String getAddress2() { 
63           return address2; 
64       } 
65    
66       public String getName() { 
67           return 
68                   firstName + 
69                   " " + lastName; 
70       } 
71    
72       public void print() { 
73           println("Name:" + getLastName()); 
74   //println("Address1:"+getAddress1()); 
75   //println("Address2:"+getAddress2()); 
76   //println("Phone1:"+getPhone1()); 
77   //println("Phone2:"+getPhone2()); 
78       } 
79    
80       public void println(Object o) { 
81           System.out.println(o); 
82       } 
83    
84       public AddressRecord(String s[]) { 
85    
86           for (int i = 0; i < s.length; i++) { 
87               switch (i) { 
88                   case 1: 
89                       firstName = s[1]; 
90                       break; 
91                   case 2: 
92                       lastName = s[2]; 
93                       break; 
94                   case 3: 
95                       lastName = s[3]; 
96                       break; 
97                   case 7: 
98                       address1 = s[3] + 
99                               "\n" + s[4] + " " 
100                              + s[5] + " " 
101                              + s[6] + " " 
102                              + s[7]; 
103                      break; 
104                  case 8: 
105                      address2 = s[8]; 
106                      break; 
107                  case 9: 
108                      phone1 = s[9]; 
109                      break; 
110                  case 10: 
111                      phone2 = s[10]; 
112                      break; 
113                  case 11: 
114                      phone3 = s[11]; 
115                      break; 
116              } 
117          } 
118      } 
119   
120      public AddressRecord() { 
121          String firstName = "doug"; 
122          String lastName = " lyon"; 
123          String address1 = "300 North Benson Rd."; 
124          String address2 = "Fairfield CT 06460"; 
125          String phone1 = "203-641-6293"; 
126          String phone2 = "203-254-4000x3155"; 
127          String phone3 = "203-877-4187 fax"; 
128      } 
129   
130   
131  } 
132