/** * */ package people; import java.util.Calendar; /** * A person who considers themself a Hokie * * @author maellis1 * @version May 2020 * */ public class Hokie { private String pid; private String hometown; private int graduationYear; private int DOBYear; /** * Constructor * * @param pid * personal id associated with Virginia Tech */ public Hokie(String newPID) { pid = newPID; } /** * Constructor * * @param pid * personal id associated with Virginia Tech * @param graduationYear */ public Hokie(String hokiePID, int graduationYear) { pid = hokiePID; this.graduationYear = graduationYear; } /** * setter for graduation year * * @param gradYear */ public void setGradYear(int gradYear) { this.graduationYear = gradYear; } /** * setter for hometown * * @param hometown */ public void setHometown(String hometown) { this.hometown = hometown; } /** * getter for graduation year * * @return year of graduation */ public int getGradYear() { return graduationYear; } /** * getter for pid * * @return pid */ public String getPID() { return pid; } /** * getter for hometown * * @return hometown */ public String getHometown() { return hometown; } /** * Returns an int representing this Hokie's data of birth * * @return year of date of birth as an int */ public int getDOBYear() { return DOBYear; } /** * Sets birth year if between 0 and 3000, returns true if successful * * @param birth year */ public boolean setDOBYear(int year) { if (year > 0 && (year < 3000)) { DOBYear = year; return true; } return false; } /** * Determines next reunion year based on reunions every 5 years * Note: does not include this year * * @return year of next Reunion */ public int nextReunion() { int currYear; currYear = Calendar.getInstance().get(Calendar.YEAR); // use modulo int yearDiff = currYear - graduationYear; if (yearDiff <= 0) return currYear + (5 - yearDiff); else return currYear + (5 - (yearDiff % 5)); // could use a loop //int checkYear = graduationYear + 5; //while (checkYear < currYear) // checkYear += 5; //return checkYear; } /** * Determines whether the current object matches its argument. * * @param obj * The object to be compared to the current object * @return true if the objects have the same name and address; * otherwise, return false */ @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (this.getClass() == obj.getClass()) { Hokie other = (Hokie)obj; return pid.equals(other.pid) && graduationYear == other.graduationYear; } else { return false; } } /** * Returns a string representing this Hokie * * @return pid as a string */ public String toString() { return pid; } /** * one class in a program can have a main method * it is the entry point for a program if it is run as an application * * @param args */ public static void main(String[] args) { Hokie bruceSmith = new Hokie("bsmith", 1984); int saveTheDate = bruceSmith.nextReunion(); System.out.println("Be in Blacksburg, Homecoming " + saveTheDate + "!"); } }