Hi all, my assignment is to create an array based ER that has patients. Each Patient has a name, id, and priority. Although a patient can be created with any id number, the id is really just replaced with a static id starting at 1000 and incremented for each Patient object created. A Triage class holds an array of a maximum of 100 Patient objects. Within the Triage class, we can addNewPatient(), removePatient(), and moveByPriority().

The array should sort each patient first by their priority (lowest first) and then by the order in which they were added to the array. I have created a helper method sortPatients() for such purposes:

Code:
	public void sortPatients(Patient[] p)
	{
		boolean doMore = true;
		while (doMore) {
			doMore = false;
			for (int i = patients - 1; i >= 0; i--) {
				if (i-1 >= 0 && patientList[i].getPriority() < patientList[i-1].getPriority()) {
					Patient temp = patientList[i];
					patientList[i] = patientList[i-1];
					patientList[i-1] = temp;
					doMore = true;
				}
			}
		}
	}
This helper method doesn't seem to swap anything and I can't figure out the error in my logic. I've tried writing out example cases, but I still can't pinpoint the error:

Code:
patientList[0] has priority 3
patientList[1] has priority 1
patients = 2

int i = 2-1 = 1 >= 0 is true
patientList[1].getPriority() < patienList[0].getPriority()
1 < 3 is true

Patient temp = patientList[1] which has priority 1
patientList[1] = patientList[0] which has priority 3
patientList[0] = temp which has priority 1
It just doesn't seem to swap any of the Patient objects when I run a test. We are not allowed to use ArrayList for this project, so I am also confused as to how to code my removePatient() method. If I have added a Patient object into an array and I want to remove that object, how do I go about doing so? Do I simply assign that Patient object's variables to null and 0?

Here is my complete code:

Patient class
Code:
package csc216project1;
import java.util.Scanner;

public class Patient {
	
	public Patient(String name, int priority) {
		nextID++;
		this.name = name;
		this.priority = priority;
		this.id = nextID;
	}
	public Patient(String name, int priority, int id) {
		nextID++;
		this.name = name;
		this.priority = priority;
		this.id = nextID;
	}
	
	public String getName() {
		return name;
	}
	public int getId() {
		return id;
	}
	public int getPriority() {
		return priority;
	}
	public void setPriority(int priority) {
		this.priority = priority;
	}

	public static Patient parseFromLine(String s) {
		Scanner scanner = new Scanner(s);
		int tempId = scanner.nextInt();
		int tempPriority = scanner.nextInt();
		String tempName = scanner.nextLine();
		Patient temp = new Patient(tempName, tempPriority, tempId);
		return temp;
	}
	
	private String name;
	private int id;
	private int priority;
	private static int nextID = 999;
	
}
Triage class
Code:
package csc216project1;

import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;

public class Triage {
	
	public Triage() {
		patientList = new Patient[100];
	}
	public Triage(String s) {
		patientList = new Patient[100];
		
		try {
			File myFile = new File(s);
			Scanner fileScanner = new Scanner(s);
			String trash = fileScanner.nextLine();
			int i = 0;
			while (fileScanner.hasNext()) {
				patientList[i] = Patient.parseFromLine(fileScanner.nextLine());
				i++;
			}
			sortPatients(patientList);
		} catch (Exception e) {
			System.exit(1);
		}
		
	}
	
	public int getSize() {
		return patients;
	}
	public void addNewPatient(String name, int priority) {
		Patient temp = new Patient(name, priority);
		int i = patients;
		patientList[i] = temp;
		sortPatients(patientList);
		patients++;
	}
	public void removePatient(int id) {
		for (int i = 0; i < patientList.length; i++) {
			if (patientList[i].getId() == id) {
				//patientList.remove(i);
			}
		}
	}
	public void moveByPriority(int id, int newPriority) {
		for (int i = 0; i < patientList.length; i++) {
			if (patientList[i].getId() == id) {
				patientList[i].setPriority(newPriority);
			}
		}
		//sortPatients(patientList);
	}
	public Patient getPatientAt(int index) {
		return patientList[index];
	}
	public String print() {
		String message = String.format("%-9s%-5s%s", "Priority", "ID", "Name");
		for (int i = 0; i < patients; i++) {
			String patient = String.format("\n%-9s%-5s%s", patientList[i].getPriority(), patientList[i].getId(), patientList[i].getName());
			message += patient;
		}
		return message;
	}
	public void printToFile() {
		
	}
	public void sortPatients(Patient[] p)
	{
		boolean doMore = true;
		while (doMore) {
			doMore = false;
			for (int i = patients - 1; i >= 0; i--) {
				if (i-1 >= 0 && patientList[i].getPriority() < patientList[i-1].getPriority()) {
					Patient temp = patientList[i];
					patientList[i] = patientList[i-1];
					patientList[i-1] = temp;
					doMore = true;
				}
			}
		}
	}

	private Patient[] patientList;
	private int patients;
	
	public static void main(String[] args) {
		Triage t = new Triage();
		t.addNewPatient("Raphael", 3);
		t.addNewPatient("Lexi", 1);
		System.out.println(t.getPatientAt(1).getName());
		System.out.println( t.print());
	}

}
Thanks in advance for anyone who is able to help.