/* File Name: registrar.java * * Purpose: Main class which runs the program * * Name: Haresh Modha * * Instructor: Leonidas Deligiannidis, Ph.D. */ import java.util.Scanner; import java.io.*; import java.lang.*; import java.util.*; public class Registrar { public static void main (String[] args) { int input = 0; String file, file2; FileReader theFile; BufferedReader fileIn = null; String phrase = null; String phrase2 = null; StudentList list = new StudentList(); Student2List list2 = new Student2List(); Scanner scan = new Scanner(System.in); System.out.println("Assignment 8"); System.out.println(); System.out.print("Enter the name of the first read-in file including the extension: "); file = scan.next(); System.out.print("Enter the name of the second read-in file including the extension: "); file2 = scan.next(); try { //reads from file BufferedReader in = new BufferedReader(new FileReader(file)); while ((phrase = in.readLine()) != null) { StringTokenizer tokens = new StringTokenizer(phrase, "[:,]"); while(tokens.hasMoreTokens()) { list.add (new Student(tokens.nextToken(),tokens.nextToken(),tokens.nextToken(),tokens.nextToken(), tokens.nextToken(),tokens.nextToken(),tokens.nextToken(),tokens.nextToken(), tokens.nextToken(),tokens.nextToken())); } } } catch (IOException e) {} try { //reads from file BufferedReader in = new BufferedReader(new FileReader(file)); BufferedReader in2 = new BufferedReader(new FileReader(file2)); while ((phrase = in.readLine()) != null) { phrase2 = in2.readLine(); StringTokenizer tokens = new StringTokenizer(phrase, "[:,]"); StringTokenizer tokens2 = new StringTokenizer(phrase2, "[:]"); tokens2.nextToken(); while(tokens.hasMoreTokens()) { list2.add (new Student2(tokens.nextToken(),tokens.nextToken(),tokens.nextToken(),tokens.nextToken(), tokens.nextToken(),tokens.nextToken(),tokens.nextToken(),tokens.nextToken(), tokens.nextToken(),tokens.nextToken(),tokens2.nextToken())); } } } catch (IOException e) {} while(input != 9) { System.out.println("\nMenu:"); System.out.println(); System.out.println("Press 1 to search for a student based on his/her last name"); System.out.println("Press 2 to search based on student ID"); System.out.println("Press 3 to print all students in the database"); System.out.println("Press 4 to print all students in the database including enrolled classes"); System.out.println("Press 5 to remove a student from the database based on the student ID field"); System.out.println("Press 6 to remove a student from the database based on the student's last name"); System.out.println("Press 7 to print all students that are enrolled in a particular course"); System.out.println("Press 8 to remove a course a student is enrolled in from his/her record"); System.out.println("Press 9 to save and terminate the application"); System.out.println(); System.out.print("Choice: "); input = scan.nextInt(); System.out.println(); switch (input) { case 1: //something break; case 2: //something break; case 3: System.out.print(list); break; case 4: System.out.print(list2); break; case 5: //something break; case 6: //something break; case 7: //something break; case 8: //something break; case 9: System.exit(-1); break; } } } }