import java.lang.*;
/** * Class Person holds information entirely belonging to one person. * * @author Michael Opel, Peter Rüßmann * @version 28.11.2003 */ class Person implements Cloneable { private String name; private String yearOfBirth; private Adresse address;
/** * Create a person with given name, age, and address. */ Person(String name, String yearOfBirth, String street, String town, String postcode, String country) { this.name = name; this.yearOfBirth = yearOfBirth; this.address = new Adresse(street,town, postcode, country); }
/** * Set a new name for the Person. * @param newName The name to become valid for the Person. */ public void setName(String newName) { this.name = newName; }
/** * Return the name of the Person. * @return The name of the Person. */ public String getName() { return this.name; }
/** * Set a new year of birth for the Person. */ public void setYearOfBirth(String newYearOfBirth) { this.yearOfBirth = newYearOfBirth; }
/** * Get the year of birth of the Person. * @return The year of birth of the Person. */ public String getYearOfBirth() { return this.yearOfBirth; }
/** * Get a string representation of the Person. * @return The detailed string representation of the Person. */ public String toString() // redefined from "Object" { return this.name + "\n" + this.yearOfBirth + "\n" + this.address.toString(); }
/** * Compares string representation of the Person. * @return The detailed string representation of the Person. */ public boolean lessThan(Person person) { char[] thisCharArray = this.name.toCharArray(); char[] personCharArray = person.getName().toCharArray();
int minLength = java.lang.Math.min(thisCharArray.length, personCharArray.length);
for (int i = 0; i < minLength; i++) { int thisChar = (int)thisCharArray[i]; int persChar = (int)personCharArray[i]; if (thisChar < persChar) return true; if (thisChar > persChar) return false; }
if (thisCharArray.length < personCharArray.length) return true; else return false; }
public Object clone() { return new Person(this.name, this.yearOfBirth, this.address.getStreet(), this.address.getTown(), this.address.getPostCode(), this.address.getCountry()); }
}