Source of Person.java


  1: //Person.java
  2: 
  3: package javadocsample;
  4: 
  5: /**
  6:  * A simple class for a person.
  7:  */
  8: public class Person
  9: {
 10:     private String name;
 11: 
 12: 
 13:     /**
 14:      * Creates a "default" person.
 15:      */
 16:     public Person()
 17:     {
 18:         name = "No name yet.";
 19:     }
 20: 
 21:     /**
 22:      * Creates a person with a specified name.
 23:      * @param initialName The person's name.
 24:      */
 25:     public Person
 26:     (
 27:         String initialName
 28:     )
 29:     {
 30:         name = initialName;
 31:     }
 32: 
 33:     /**
 34:      * Sets the name of the person.
 35:      * @param newName The person's name is changed to newName.
 36:      */
 37:     public void setName
 38:     (
 39:         String newName
 40:     )
 41:     {
 42:         name = newName;
 43:     }
 44: 
 45:     /**
 46:      * Gets the name of the person.
 47:      * @return The person's name.
 48:      */
 49:     public String getName()
 50:     {
 51:         return name;
 52:     }
 53: 
 54:     /**
 55:      * Displays the name of the person.
 56:      */
 57:     public void writeOutput()
 58:     {
 59:         System.out.println("Name: " + name);
 60:     }
 61: 
 62:     /**
 63:      * Tests whether this person has the same name as another person.
 64:      * @return true only if calling object and otherPerson have the same name.
 65:      */
 66:     public boolean sameName
 67:     (
 68:         Person otherPerson
 69:     )
 70:     {
 71:         return (this.name.equalsIgnoreCase(otherPerson.name));
 72:     }
 73: }
 74: