<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Person.java</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style type="text/css"> <!-- body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace} pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace} table {color: #888888; background-color: #313335; font-family: monospace} .ST2 {color: #9876aa} .ST3 {color: #ffc66d} .string {color: #6a8759} .number {color: #6897bb} .comment {color: #808080} .whitespace {color: #505050} .ST5 {color: #ffc66d; font-family: monospace; font-style: italic} .ST6 {color: #9876aa; font-family: monospace; font-style: italic} .ST1 {color: #808080; font-family: monospace; font-weight: bold} .ST0 {color: #287bde} .literal {color: #cc7832} .ST4 {font-family: monospace; font-style: italic} --> </style> </head> <body> <table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Exams/PracticeExam1/src/main/java/com/calebfontenot/practiceexam1/Person.java</td></tr></table> <pre> <span class="comment">/*</span> <span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span> <span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span> <span class="comment"> */</span> <span class="literal">package</span> com.calebfontenot.practiceexam1; <span class="literal">import</span> java.util.GregorianCalendar; <span class="literal">import</span> java.util.Objects; <span class="comment">/**</span> <span class="comment"> *</span> <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span> <span class="comment">*/</span> <span class="literal">public</span> <span class="literal">class</span> Person { <span class="literal">private</span> String <span class="ST2">name</span>; <span class="literal">private</span> <span class="literal">final</span> GregorianCalendar <span class="ST2">birthDate</span>; <span class="literal">public</span> Person(String name, GregorianCalendar brithDate) { <span class="literal">this</span>.<span class="ST2">name</span> = name; <span class="literal">this</span>.<span class="ST2">birthDate</span> = brithDate; } <span class="literal">public</span> String <span class="ST3">getName</span>() { <span class="literal">return</span> <span class="ST2">name</span>; } <span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setName</span>(String name) { <span class="literal">this</span>.<span class="ST2">name</span> = name; } <span class="literal">public</span> GregorianCalendar <span class="ST3">getBirthdate</span>() { <span class="literal">return</span> <span class="literal">this</span>.<span class="ST2">birthDate</span>; } @Override <span class="literal">public</span> <span class="literal">boolean</span> <span class="ST3">equals</span>(Object obj) { <span class="literal">if</span> (<span class="literal">this</span> == obj) { <span class="literal">return</span> <span class="literal">true</span>; } <span class="literal">if</span> (obj == <span class="literal">null</span>) { <span class="literal">return</span> <span class="literal">false</span>; } <span class="literal">if</span> (getClass() != obj.getClass()) { <span class="literal">return</span> <span class="literal">false</span>; } <span class="literal">final</span> Person other = (Person) obj; <span class="literal">if</span> (!Objects.<span class="ST4">equals</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">name</span>, other.<span class="ST2">name</span>)) { <span class="literal">return</span> <span class="literal">false</span>; } <span class="literal">return</span> Objects.<span class="ST4">equals</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">birthDate</span>, other.<span class="ST2">birthDate</span>); } @Override <span class="literal">public</span> String <span class="ST3">toString</span>() { <span class="literal">return</span> <span class="string">"</span><span class="string">Person{</span><span class="string">"</span> + <span class="string">"</span><span class="string">name=</span><span class="string">"</span> + <span class="ST2">name</span> + <span class="string">"</span><span class="string">, birthDate=</span><span class="string">"</span> + <span class="ST2">birthDate</span>.toInstant() + <span class="string">'</span><span class="string">}</span><span class="string">'</span>; } <span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) { Person john = <span class="literal">new</span> Person(<span class="string">"</span><span class="string">John</span><span class="string">"</span>, <span class="literal">new</span> GregorianCalendar(<span class="number">2</span><span class="number">003</span>, <span class="number">8</span>, <span class="number">2</span><span class="number">8</span>)); Person mary = <span class="literal">new</span> Person(<span class="string">"</span><span class="string">Mary</span><span class="string">"</span>, <span class="literal">new</span> GregorianCalendar(<span class="number">2</span><span class="number">004</span>, <span class="number">3</span>, <span class="number">2</span><span class="number">3</span>)); System.<span class="ST6">out</span>.println(john); System.<span class="ST6">out</span>.println(mary); Person john1 = <span class="literal">new</span> Person(<span class="string">"</span><span class="string">John</span><span class="string">"</span>, <span class="literal">new</span> GregorianCalendar(<span class="number">2</span><span class="number">003</span>, <span class="number">8</span>, <span class="number">2</span><span class="number">8</span>)); Person john2 = <span class="literal">new</span> Person(<span class="string">"</span><span class="string">John</span><span class="string">"</span>, <span class="literal">new</span> GregorianCalendar(<span class="number">2</span><span class="number">003</span>, <span class="number">1</span><span class="number">0</span>, <span class="number">1</span><span class="number">0</span>)); Person john3 = <span class="literal">new</span> Person(<span class="string">"</span><span class="string">John</span><span class="string">"</span>, <span class="literal">new</span> GregorianCalendar(<span class="number">2</span><span class="number">003</span>, <span class="number">8</span>, <span class="number">2</span><span class="number">8</span>)); System.<span class="ST6">out</span>.println(john1.equals(john)); System.<span class="ST6">out</span>.println(john2.equals(john)); System.<span class="ST6">out</span>.println(john3.equals(john)); } } </pre></body> </html>