/* Author: James Tam Version: Feb. 4B, 2021 Learning objective: This version augments the previous version by including a toString method. */ public class Person { public static final String DEFAULT_NAME = "No name"; public static final int DEFAULT_AGE = -1; private int age; private String name; public Person() { this(DEFAULT_NAME,DEFAULT_AGE); } public Person(String newName, int newAge) { setName(newName); setAge(newAge); } //Returns true: age and name of both objects identical, false is //returned otherwise. //Reminders: //1) 'this' refers to the object whose equals method was called // (implicit parameter). //2) 'anotherPerson' is the object being compared to which is // passed explicitly as a parameter. public boolean equals(Person anotherPerson) { final int SAME_NAME = 0; boolean sameObject = true; //The use of 'this' isn't mandatory but used to make it //obvious that two separate objects are compared. if (this.name.compareToIgnoreCase(anotherPerson.name) != SAME_NAME) { sameObject = false; } else if (this.age != anotherPerson.age) { sameObject = false; } return(sameObject); } public int getAge() { return(age); } public String getName() { return(name); } public void setAge(int newAge) { age = newAge; } public void setName(String newName) { name = newName; } //toString() //Arguments: none //Return: a string representation of the state of the object. //Format for the exercise: //Name:, Age: public String toString() { String objectState = null; //Students implement your solution here. return(objectState); } }