import java.io.*; //-------------------------------------------------------------- // InteractiveGrades.java // CS100 P3Q2 // // Wei Tsang Ooi 16 July 1999 // // This program prompts the user for a list of students and their // grades, then summarises their final score and pass/fail status. // //-------------------------------------------------------------- class InteractiveGrades extends Grades { static final int NUM_OF_OPTIONS = 5; static final int SEARCH_NAME = 1; static final int SHOW_STATS = 2; static final int SHOW_LETTER_GRADE = 3; static final int SHOW_ALL = 4; static final int QUIT = 5; static final String PROMPT_MESSAGE[] = { "Search for a particular name and view that person's grade.", "View the maximum, minimum and average grades for the entire class.", "View the names and average grades of the students who were taking\n" + " the class for a letter grade.", "View the entire list of students and all of their grades.", "Quit" }; //---------------------------------------------------------- // getOption // // prompt the user for an option. Returns the option entered // by the user. This option is guranteed to be one of "QUIT" // "SEARCH_NAME", "SHOW_STATS", "SHOW_LETTER_GRADE" or // "SHOW_ALL" //---------------------------------------------------------- static int getOption() throws IOException { int option; System.out.println(); do { System.out.println("Enter You Option :"); for (int i = 0; i < NUM_OF_OPTIONS; i++) { System.out.print("[" + (i+1) + "] : "); System.out.println(PROMPT_MESSAGE[i]); } option = Integer.parseInt(stdin.readLine()); } while (option < 1 || option > NUM_OF_OPTIONS); return option; } public static void main (String args[]) throws IOException { // This program create a class and supply a few otions // for user : // - display grades of a specified student // - display max/min/mean grades of the class // - display grades of students taking the class for letter grade // - display grades of all students stdin = new BufferedReader(new InputStreamReader(System.in)); Class cs100 = createClass(); int option = getOption(); while (option != QUIT) { switch (option) { case SEARCH_NAME : String name = getName(); cs100.printStudent(name); break; case SHOW_STATS : cs100.printStats(); break; case SHOW_LETTER_GRADE : cs100.printLetterGradeStudents(); break; case SHOW_ALL : cs100.printAllStudents(); break; } option = getOption(); } } }