Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The Person Class uses get methods and returns appropriate data
- // Renee Waggoner
- // July 17, 2019
- // Special Requirements: None
- package family;
- public class Person {
- private String name;
- private int age;
- // default constructor, no parameters
- public Person() {
- }
- // constructor with 2 parameters
- public Person(String name, int age)
- {
- this.name = name;
- this.age = age;
- }
- // using toString allows us to return values without writing as much code
- public String toString()
- {
- return "Person [name: " + name + ", age: " + age + "]";
- }
- public boolean equals(Object obj)
- {
- // creating path for display data
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Person other = (Person) obj;
- if (age != other.age)
- return false;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- return true;
- }
- // call getName method to return name
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment