// purpose: represent a person public class Person { // attributes String id; int age; String sex; String favorite; // constructors -- person configurers // Person(): default person public Person() { this.setId( "Superman" ); this.setAge( 27 ); this.setFavorite( "Truth, justice, and the American way" ); } // Person: specified person public Person( String n, int a, String f ) { this.setId( n ); this.setAge( a ); this.setFavorite( f ); } // inspectors -- accessors to a person's information // getId(): give back the person's id public String getId() { return this.id; } // getAge(): give back the person's age public int getAge() { return this.age; } // getFavorite(): give back the person's favorite public String getFavorite() { return this.favorite; } // mutators -- modifiers of a person's information // setId(): update the person's id public void setId( String n ) { if ( n.length() != 0 ) { this.id = n; } } // setAge(): update the person's age public void setAge( int a) { if ( ( a >= 18 ) && ( a <= 100 ) ) { this.age = a; } } // setFavorite(): update the person's favorite public void setFavorite( String f ) { if ( f.length() != 0 ) { this.favorite = f; } } // other behaviors public String toString() { String n = this.getId(); int a = this.getAge(); String f = this.getFavorite(); String representation = "Person( " + n + ", " + a + ", " + f + " )"; return representation; } public boolean equals( Object other ) { if ( other instanceof Person ) { Person p = (Person) other; String n1 = this.getId(); String n2 = p.getId(); int a1 = this.getAge(); int a2 = p.getAge(); String f1 = this.getFavorite(); String f2 = p.getFavorite(); return ( n1.equals( n2 ) && ( a1 == a2 ) && f1.equals( f2 ) ); } else { return false; } } }