The assignment asks for entry of 10 patient records, to include patientId, patientFirstName, patientLastName, patientIllness, and notes; this is to be put into a TreeSet with a Comparator that will abc by last name.
This is the section of code that I am struggling with:
public void patientRecord() {
int i = 0;
int patientRecords = 10;
Set<Patient> patientHashSet;
System.out.println("This program will create ten patient records.");
System.out.println();
do {
getPatientId();
getPatientFirstName();
getPatientLastName();
getPatientIllness();
getNotes();
patientHashSet = new TreeSet<>(new PatientComparator());
patientHashSet.add(new Patient(patientId, patientFirstName, patientLastName, patientIllness, notes));
i++;
} while (i < patientRecords);
for (Patient record : patientHashSet) {
System.out.println(record.patientId + " " + record.patientLastName + ", " + record.patientFirstName + " "
+ record.patientIllness + " " + record.notes);
System.out.println("##########################################################################");
}
}
And this is the Comparator code:
import java.util.Comparator;
public class PatientComparator implements Comparator<Patient> {
@Override
public int compare(Patient o1, Patient o2) {
return o1.patientLastName.compareTo(o2.patientLastName);
}
}
I'm not really sure what it is that I'm doing wrong. I have also tried placing the "add" into an array, but that produces the same results--only the last patient's information prints out, along with the line of "####".