/* Craig Persiko  -  SearchGroup.java - CS 111A

   A program which asks the user to enter the last 4 digits of their 
   student ID number, and then searches an array representing a special 
   group of student IDs, to see if the number entered is found in the array.
   If the ID is found in the array, tell the user which element it is.
   If the ID is not found, tell the user that.
*/

import java.io.*;

class SearchGroup
{
  public static void main(String args[]) throws IOException
  {
    int id, pos;
    // This BufferedReader is like a Scanner. It's an older way of getting
    // keyboard input.
    BufferedReader keyIn = new BufferedReader(
                             new InputStreamReader(System.in));

    System.out.println("Please enter the last 4 digits of your student ID.");
    id = Integer.parseInt(keyIn.readLine());

    pos = inGroup(id);
    if(pos > -1)
      System.out.println("You are the number " + pos
                         + " person in the special group.");
    else
    {
      System.out.println("You are not in the special group.");
      System.out.println("(Don't fret!  You're still special)");
    }
  }

  // searches the final array defined in this function for the id specified,
  // returns -1 if it can't be found, or the array index if it is found.
  static int inGroup(int id)
  {
    final int[] GROUP_IDS = {1218, 1391, 1529, 2019, 2233,
                             2689, 2778, 3212, 3286, 3910,
                             4192, 4270, 4444, 4619, 4639,
                             4687, 5107, 5530, 5550, 5884};

    for(int i=0; i < GROUP_IDS.length; i++)
      if(id == GROUP_IDS[i])
        return i;

    return -1;
  }
}
/* Sample Output:

$ java SearchGroup
Please enter the last 4 digits of your student ID.
3343
You are not in the special group.
(Don't fret!  You're still special)
$ java SearchGroup
Please enter the last 4 digits of your student ID.
4444
You are the number 12 person in the special group.
$ java SearchGroup
Please enter the last 4 digits of your student ID.
4444444
You are not in the special group.
(Don't fret!  You're still special)
$ java SearchGroup
Please enter the last 4 digits of your student ID.
1218
You are the number 0 person in the special group.

*/


syntax highlighted by Code2HTML, v. 0.9