Advertisement
Slyke

W281

Sep 11th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. ///////////// PROBLEM STATEMENT //////////////////
  2. // The problem statement is in file Person.pdf. //
  3. //////////////////////////////////////////////////
  4.  
  5. public class W281 {public static void main(String[] args) {while (JPL.test()){  
  6.   Person person1 = new Person("Joe", "Smith", 28);
  7.   Person person2 = new Person("John", "Jones", 56);
  8.   Person person3 = new Person("Brenda", "Smith", 33);
  9.   System.out.println(person1 + " " + person2 + " " + person3);
  10.   System.out.println(person1.equals(person2));
  11.   Person person4 = person1;
  12.   System.out.println(person1.equals(person4));
  13. }}}
  14.  
  15. // ****************************************************************
  16. // Person.java // // A class that represents a person.
  17. // ****************************************************************
  18. class Person
  19. {private String firstName;    
  20.   private String lastName;    
  21.   private int age;
  22.  
  23.   public boolean equals(Person theOther)
  24.   {
  25.     if (theOther.getFirstName()==this.firstName)
  26.     {
  27.       if (theOther.getLastName()==this.lastName)
  28.       {
  29.         if (theOther.getAge()==this.age)
  30.         {
  31.           return true;
  32.         }
  33.       }
  34.     }
  35.     return false;
  36.   }
  37.  
  38.   public String toString()
  39.   {
  40.     return firstName + " " + lastName + " " + age;
  41.   }
  42.  
  43.   public Person (String newFirstName, String newLastName, int newAge)    
  44.   {firstName = newFirstName;      
  45.     lastName = newLastName;      
  46.     age = newAge;    
  47.   }        
  48.  
  49.   public String getFirstName()    
  50.   {return firstName;    
  51.   }        
  52.  
  53.   public String getLastName()    
  54.   {return lastName;    
  55.   }        
  56.  
  57.   public int getAge()    
  58.   {return age;    
  59.   }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement