001 package market;
002
003 /* Generated by Together */
004 import java.util.Calendar;
005
006 import users.User;
007
008 /**
009 * A person that interacts with the market. Can be a {@link UCustomer customer} or an
010 * {@link UStaffer employee}.
011 */
012 public class UPerson extends User {
013
014 public static String HERR = new String("Herr");
015 public static String FRAU = new String("Frau");
016
017 private String salutation;
018 private String name;
019 private String firstName;
020 private String street;
021 private int postcode;
022 private String city;
023 private String telephone;
024 private Calendar date;
025
026 /**
027 * Creates a new person.
028 * @param userName the person's ID.
029 */
030 public UPerson(String userName){
031 super(userName);
032 date = (Calendar)SMarket.getTime().clone();
033 }
034
035 /**
036 * Sets the person's name.
037 * @param salutation the person's salutation (Mr, Mrs)
038 * @param name the person's surname.
039 * @param firstName the person's forename.
040 */
041 public void setFullName(String salutation, String name, String firstName) {
042 this.salutation = salutation;
043 this.name = name;
044 this.firstName = firstName;
045 }
046
047 /**
048 * Sets the person's address.
049 */
050 public void setAddress(String street, int postcode, String city) {
051 this.street = street;
052 this.postcode = postcode;
053 this.city = city;
054 }
055
056 /**
057 * Sets the person's telephone number.
058 */
059 public void setTelephone(String telephone) {
060 this.telephone = telephone;
061 }
062
063 /**
064 * Gets the person's name.
065 * @return the full name, containing salutation, forename and surname.
066 */
067 public String getFullName() {
068 return (salutation + " " + firstName + " " + name);
069 }
070
071 /**
072 * Gets the person's address.
073 * @return the address, containing street, postcode and city.
074 */
075 public String getAdress() {
076 return (street + Integer.toString(postcode) + city);
077 }
078
079 /**
080 * Gets the person's telephone number.
081 * @return the telephone number.
082 */
083 public String getTelephone() {
084 return telephone;
085 }
086
087 /**
088 * Gets the person's salutation.
089 * @return the salutation.
090 */
091 public String getSalutation() {
092 return salutation;
093 }
094
095 /**
096 * Sets the person's salutation.
097 * @param salutation the salutation to be set.
098 */
099 public void setSalutation(String salutation) {
100 this.salutation = salutation;
101 }
102
103 /**
104 * Gets the person's surname.
105 * @return the surname.
106 */
107 public String getSurname() {
108 return name;
109 }
110
111 /**
112 * Sets the person's surname.
113 * @param name the surname to be set.
114 */
115 public void setSurname(String name) {
116 this.name = name;
117 }
118
119 /**
120 * Gets the person's forename.
121 * @return the forename.
122 */
123 public String getFirstName() {
124 return firstName;
125 }
126
127 /**
128 * Sets the person's forename.
129 * @param firstName the forename to be set.
130 */
131 public void setFirstName(String firstName) {
132 this.firstName = firstName;
133 }
134
135 /**
136 * Gets the street where the person lives.
137 * @return the street.
138 */
139 public String getStreet() {
140 return street;
141 }
142
143 /**
144 * Sets the street where the person lives.
145 * @param street the street to be set.
146 */
147 public void setStreet(String street) {
148 this.street = street;
149 }
150
151 /**
152 * Gets the person's postcode.
153 * @return the postcode.
154 */
155 public int getPostcode() {
156 return postcode;
157 }
158
159 /**
160 * Sets the person's postcode.
161 * @param postcode the postcode to be set.
162 */
163 public void setPostcode(int postcode) {
164 this.postcode = postcode;
165 }
166
167 /**
168 * Gets the city where the person lives.
169 * @return the city.
170 */
171 public String getCity() {
172 return city;
173 }
174
175 /**
176 * Sets the city where the person lives.
177 * @param city the city.
178 */
179 public void setCity(String city) {
180 this.city = city;
181 }
182
183 /**
184 * Gets the day the person has first had contact with the market.<br>
185 * For customer this is the registration, for workers the day of employment.
186 *
187 * @return the date registration or employment.
188 */
189 public Calendar getDayOfRegistration() {
190 return date;
191 }
192
193 /**
194 * Returns the time in months the person has been part of the market, be it as customer or worker.
195 * @return the time of membership or employment.
196 * @see #getDayOfRegistration
197 */
198 public int getMonthsOfMembership() {
199 Calendar start = (Calendar)date.clone();
200 Calendar now = SMarket.getTime();
201 int months = 12 * (now.get(Calendar.YEAR) - start.get(Calendar.YEAR));
202 months += now.get(Calendar.MONTH) - start.get(Calendar.MONTH);
203 if (start.get(Calendar.DATE) > now.get(Calendar.DATE)) months--;
204 return months;
205 }
206
207 /**
208 * Sets the default comparison order for UPersons to <surname, forename>
209 */
210 public int compareTo(Object o) {
211 if (o instanceof UPerson) {
212 UPerson u = (UPerson) o;
213 return new String(getSurname() + getFirstName()).compareTo(
214 new String(u.getSurname() + u.getFirstName()));
215 } else {
216 return 0;
217 }
218 }
219 }