Source of Person.java


  1: //Person.java
  2: 
  3: public class Person
  4: {
  5:     private String name;
  6:     
  7:     public Person()
  8:     {
  9:         name = "No name yet";
 10:     }
 11:     
 12:     public Person
 13:     (
 14:         String initialName //in
 15:     )
 16:     {
 17:         name = initialName;
 18:     }
 19:     
 20:     public void setName
 21:     (
 22:         String newName //in
 23:     )
 24:     {
 25:         name = newName;
 26:     }
 27:     
 28:     public String getName()
 29:     {
 30:         return name;
 31:     }
 32:     
 33:     public void writeOutput()
 34:     {
 35:         System.out.println("Name: " + name);
 36:     }
 37:    
 38:     public boolean hasSameName
 39:     (
 40:         Person otherPerson //in
 41:     )
 42:     {
 43:         return this.name.equalsIgnoreCase(otherPerson.name);
 44:     }
 45: 
 46:     public static void main(String[] args)
 47:     {
 48:         Person person1 = new Person();
 49:         person1.writeOutput();
 50:         Person person2 = new Person("John");
 51:         person2.writeOutput();
 52:         Person person3 = new Person("john");
 53:         person3.writeOutput();
 54:         System.out.println(person2.hasSameName(person3));
 55:     }
 56: }
 57: