// A class which handles applications for university admission
import javax.swing.JOptionPane;

public class Applications {
   public static void main( String args[] ) {
  	 ApplicationCentre appCentre= new ApplicationCentre ("Guelph");
	 String stopper="quit";
                int nrStud=0;
// Input data 
            JOptionPane.showMessageDialog(null,"Enter student names, each followed by 3 choices of universities. To stop enter for name the word quit","Input", JOptionPane.PLAIN_MESSAGE);
	 String n = JOptionPane.showInputDialog("Student's name ?");
	 boolean flag=true;
	 while (!n.equals(stopper) && flag){
		 String u1= JOptionPane.showInputDialog("1st university ?");
		 String u2= JOptionPane.showInputDialog("2nd university ?");
                 String u3= JOptionPane.showInputDialog("3rd university ? ");
		 StudentApplication s=new StudentApplication (n, u1, u2, u3);
		 flag=appCentre.addStudent(s);                 n=JOptionPane.showInputDialog("Student's name ?");
                              nrStud++;
	 }

  // Accept some applications
                	
	 String line = JOptionPane.showInputDialog(" Indicate which applications are to be accepted by entering the student index number. To stop enter for name the word quit");
	 while (!line.equals(stopper)) {
	   int stnr=Integer.parseInt(line);
	   line= JOptionPane.showInputDialog("Enter university index 0..2");
	   int anr=Integer.parseInt(line);
	   appCentre.getStudent(stnr).setAcceptance(anr, true);
           line= JOptionPane.showInputDialog(" Indicate which applications are to be accepted by entering the student index number. To stop enter for name the word quit");
                }

  // Print the final results
               JOptionPane.showMessageDialog(null, " Records for all applicants to "+ appCentre.getName() + "\n","Records", JOptionPane.PLAIN_MESSAGE);
             for (int i=0;i<nrStud; i++)
               JOptionPane.showMessageDialog(null,appCentre.getStudent(i).toString() ,"Records", JOptionPane.PLAIN_MESSAGE);
   }
}


class ApplicationCentre {
  private String name;
  private StudentApplication [] st;
  private int studentCount;
  private int size;
  
  public ApplicationCentre(String s){
        name=s;
        size=100;
        st = new StudentApplication[size];
        studentCount=0;
}

  public String getName() {
        return name;
  }

  public boolean addStudent(StudentApplication s){
   if (studentCount==size) return false;
   st[studentCount]=s;
   studentCount ++;
   return true;
  }

  public StudentApplication getStudent(int which){
	if (which<0 || which > studentCount-1){
	   return null;
	}
        return st[which];
  }
}



  class StudentApplication{
	private String name;
	private String university0;
	private String university1;
	private String university2;
	private boolean accept0;
	private boolean accept1;
	private boolean accept2;

	public StudentApplication (String n, String u0, String u1, String u2){
		name = n;
		university0=u0;
		university1=u1;
		university2=u2;
		accept0=accept1=accept2=false;
	}

	public void setAcceptance(int which, boolean decision){
		switch(which){
		case 0: accept0=decision; break;
		case 1: accept1=decision; break;
		case 2: accept2=decision; break;
		}
	}

	public String toString(){
		String result = name + ":\n";
                             result += university0;
		if (accept0) result += " - accepted\n";
			else result += " - rejected\n";
   	               result += university1;
		if (accept1) result += " - accepted\n";
			else result += " - rejected\n";
                            result += university2;
		if (accept2) result += " - accepted\n";
			else result += " - rejected\n";
                            return result;
	}
  }




