Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////// PROBLEM STATEMENT //////////////////
- // The problem statement is in file Person.pdf. //
- //////////////////////////////////////////////////
- public class W281 {public static void main(String[] args) {while (JPL.test()){
- Person person1 = new Person("Joe", "Smith", 28);
- Person person2 = new Person("John", "Jones", 56);
- Person person3 = new Person("Brenda", "Smith", 33);
- System.out.println(person1 + " " + person2 + " " + person3);
- System.out.println(person1.equals(person2));
- Person person4 = person1;
- System.out.println(person1.equals(person4));
- }}}
- // ****************************************************************
- // Person.java // // A class that represents a person.
- // ****************************************************************
- class Person
- {private String firstName;
- private String lastName;
- private int age;
- public boolean equals(Person theOther)
- {
- if (theOther.getFirstName()==this.firstName)
- {
- if (theOther.getLastName()==this.lastName)
- {
- if (theOther.getAge()==this.age)
- {
- return true;
- }
- }
- }
- return false;
- }
- public String toString()
- {
- return firstName + " " + lastName + " " + age;
- }
- public Person (String newFirstName, String newLastName, int newAge)
- {firstName = newFirstName;
- lastName = newLastName;
- age = newAge;
- }
- public String getFirstName()
- {return firstName;
- }
- public String getLastName()
- {return lastName;
- }
- public int getAge()
- {return age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement