/**
* An array of Student2 !!
* We'll also sort (for fun)
*/

import java.util.Scanner;;

public class UseStudent3
{

public static void main(String[] args)
{ String first,last,tempID;
int ID;
int i;
Student2 s;
String answer;
int count=0;

final int MAX_COUNT=50;
Student2[] stuArray=new Student2[MAX_COUNT];

Scanner keyboard=new Scanner(System.in);

while(true && count<MAX_COUNT)
{
System.out.println("Enter first name");
first=keyboard.nextLine();

System.out.println("Enter last name");
last=keyboard.nextLine();

System.out.println("Enter ID");
ID=keyboard.nextInt();

/* Pesky newline character to get past !! */
keyboard.nextLine();

stuArray[count]=new Student2(first,last,ID);
count++;

System.out.println("Do you want to continue [y/n]");
answer=keyboard.nextLine();

if(answer.equals("n")) break;
}

/* Before sort */
System.out.println("Before the sort");
for(i=0;i<count;i++)
System.out.println(""+i+" "+stuArray[i]);


sortIt(stuArray,count);


/* After sort */
System.out.println("After the sort");
for (i=0;i<count;i++)
System.out.println(""+i+" "+stuArray[i]);


System.exit(0);


}

/* Sort that array !! Do you know the name of this sort ??
*/

public static void sortIt(Student2[] s, int c)
{
Student2 temp;
int i,j,k,low;


for(i=0;i<c; i++)
{ low=i;
for(j=i+1;j<c;j++)
if(s[j].compareTo(s[low])<0)
low=j;
if (low!=i)
{ temp=s[i];
s[i]=s[low];
s[low]=temp;
}
}
}



}