/**
 * @author Suzanne Balik, 19 Apr 2003
 */
 public class WaitingRoomList {

   private int numberOfPatients;
   
   private Patient[] patients;
   
   public WaitingRoomList(int size) {
   
     patients = new Patient[size];
     
     numberOfPatients = 0;
   }
   
   public int numberOfPatients() {
   
     return numberOfPatients;
   }
   
   public boolean addPatient(String name, String symptoms) {
   
     if (numberOfPatients < patients.length) {
     
       patients[numberOfPatients++] = new Patient(name, symptoms);
       
       return true;
     }
     return false;
   }
   
   public String removePatient() {
   
     if (numberOfPatients > 0) {
     
       //Get first patient's name and symptoms
       String patientInfo = patients[0].toString();
       
       //Shift the rest of the patients up one spot (left shift)
       for (int i = 0; i < numberOfPatients - 1; i++)
       
         patients[i] = patients[i+1];
	 
       //Decrement number of patients
       numberOfPatients--;
       
       //Return first patient's name and symptoms
       return patientInfo;
     }
     
     else
     
       return "No patients";
  }
 
  public String toString() {
  
    String s = "";
    for (int i = 0; i < numberOfPatients; i++)
      s += (i+1) + ". " + patients[i].toString() + "\n";
    return s;
  }
  
  public static void main(String[] args) {
  
    WaitingRoomList list = new WaitingRoomList(5);
    
    if (!list.addPatient("Britney Spears", "laryngitis"))
      System.out.println("Patient NOT added");
      
    if (!list.addPatient("Kurt Vonnegut", "writer's cramp"))
      System.out.println("Patient NOT added");
      
    if (!list.addPatient("Joseph Smith", "stomach flu"))
      System.out.println("Patient NOT added");
      
    
    System.out.println("\nPatients: \n" + list);
    
    int numberOfPatients = list.numberOfPatients();
    
    for (int i = 0; i < numberOfPatients; i++)
      System.out.println("Patient: " + list.removePatient()); 
      
    System.out.println("Patient: " + list.removePatient());
  }
}
/* PROGRAM OUTPUT:
eos% java WaitingRoomList

Patients: 
1. Britney Spears	laryngitis
2. Kurt Vonnegut	writer's cramp
3. Joseph Smith	stomach flu

Patient: Britney Spears	laryngitis
Patient: Kurt Vonnegut	writer's cramp
Patient: Joseph Smith	stomach flu
Patient: No patients
*/