/home/caleb/ASDV-Java/Semester 2/Exams/PracticeExam1/src/main/java/com/calebfontenot/practiceexam1/Person.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.practiceexam1;
import java.util.GregorianCalendar;
import java.util.Objects;
@author
public class Person {
private String name;
private final GregorianCalendar birthDate;
public Person(String name, GregorianCalendar brithDate)
{
this.name = name;
this.birthDate = brithDate;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public GregorianCalendar getBirthdate() {
return this.birthDate;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Person other = (Person) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
return Objects.equals(this.birthDate, other.birthDate);
}
@Override
public String toString()
{
return "Person{" + "name=" + name + ", birthDate=" + birthDate.toInstant() + '}';
}
public static void main(String[] args)
{
Person john = new Person("John", new GregorianCalendar(2003, 8, 28));
Person mary = new Person("Mary", new GregorianCalendar(2004, 3, 23));
System.out.println(john);
System.out.println(mary);
Person john1 = new Person("John", new GregorianCalendar(2003, 8, 28));
Person john2 = new Person("John", new GregorianCalendar(2003, 10, 10));
Person john3 = new Person("John", new GregorianCalendar(2003, 8, 28));
System.out.println(john1.equals(john));
System.out.println(john2.equals(john));
System.out.println(john3.equals(john));
}
}