import java.util.*; public class StudentRecord { private String ID; private String firstName; private String lastName; private String address; private GregorianCalendar timeModified; // Constructor with one parameter public StudentRecord(String studentID) { ID = studentID; firstName = "unknown"; lastName = "unknown"; address = "unknown"; timeModified = new GregorianCalendar(); } // Constructor with five parameters public StudentRecord(String studentID, String studentFirstName, String studentLastName, String studentAddress, GregorianCalendar studentTimeModified) { ID = studentID; firstName = studentFirstName; lastName = studentLastName; address = studentAddress; timeModified = studentTimeModified; } // mutator methods (that set specific fields) public void setAddress(String newAddress) { address = newAddress; timeModified = new GregorianCalendar(); } public void setFirstName(String newFirstName) { firstName = newFirstName; timeModified = new GregorianCalendar(); } public void setLastName(String newLastName) { lastName = newLastName; timeModified = new GregorianCalendar(); } public void setAddress() { address = "unknown"; timeModified = new GregorianCalendar(); } public void setFirstName() { firstName = "unknown"; timeModified = new GregorianCalendar(); } public void setLastName() { lastName = "unknown"; timeModified = new GregorianCalendar(); } public void setID(String newID) { ID = newID; timeModified = new GregorianCalendar(); } public void setTimeModified(GregorianCalendar newTimeModified) { timeModified = newTimeModified; } // Accessor methods public String getAddress() { return address; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getID() { return ID; } public GregorianCalendar getTimeModified() { return timeModified; } public void synchronize(StudentRecord otherRecord) { if (ID.equals(otherRecord.ID)) { int compResult; if (timeModified.before(otherRecord.getTimeModified())) compResult = -1; else if (timeModified.after(otherRecord.getTimeModified())) compResult = 1; else compResult = 0; // // If we want to implement our comparison directly // if (timeModified.get(Calendar.YEAR) < otherRecord.timeModified.get(Calendar.YEAR)) // compResult = -1; // else if (timeModified.get(Calendar.YEAR) > otherRecord.timeModified.get(Calendar.YEAR)) // compResult = 1; // else if (timeModified.get(Calendar.MONTH) < otherRecord.timeModified.get(Calendar.MONTH)) // compResult = -1; // else if (timeModified.get(Calendar.MONTH) > otherRecord.timeModified.get(Calendar.MONTH)) // compResult = 1; // else if (timeModified.get(Calendar.DAY_OF_MONTH) < otherRecord.timeModified.get(Calendar.DAY_OF_MONTH)) // compResult = -1; // else if (timeModified.get(Calendar.DAY_OF_MONTH) > otherRecord.timeModified.get(Calendar.DAY_OF_MONTH)) // compResult = 1; // else compResult = 0; if (compResult < 0) { firstName = otherRecord.getFirstName(); lastName = otherRecord.getLastName(); address = otherRecord.getAddress(); timeModified = otherRecord.getTimeModified(); } else if (compResult > 0) { otherRecord.setFirstName(firstName); otherRecord.setLastName(lastName); otherRecord.setAddress(address); otherRecord.setTimeModified(timeModified); } } } public String toString(){ return "Student ID number: " + ID + "\n" + "Student Name: " + firstName + " " + lastName + "\n" + "Student Address: " + address + "\n" + "Last time modified: " + (timeModified.get(Calendar.MONTH)+1) + "/" + timeModified.get(Calendar.DAY_OF_MONTH) + "/" + timeModified.get(Calendar.YEAR); } }