I have a method to add a patient to the correct index depending on their priority. However it seems that when I add more than one person, it doesn't get added. I'm not too sure what I'm missing in my add method. My guess is there is something wrong with the if-else statement but I'm not able to pinpoint where the problem is.
public void addPatient(Patient sickPerson)
{
int lim = patients.size();
if (patients.isEmpty()) //if empty
{
patients.add(sickPerson);
}
else //if not empty
{
for (int i = 0; i < lim; i++)
{
if (patients.get(i).compareTo(sickPerson) > 0)
// if the sickperson is more important...
{
patients.add(i, sickPerson);
}
else if (patients.get(i).compareTo(sickPerson) == 0)
// if the sickperson's priority is the same,
{
patients.add(i + 1, sickPerson);
}
else
{
continue;
}
}
}
}
@Test
public void getNumWaitingTest() {
WaitingRoom a = new WaitingRoom();
Patient b = new Patient("name", "bad", 1, 1);
Patient c = new Patient("name2", "bad2", 2, 2);
a.addPatient(b);
a.addPatient(c);
assertEquals(2, a.getNumWaiting());
}
and if I run this test case, I would get 1 for the numWaiting for some reason... where could I have gone wrong in this code??