public class BadRequests
1: import java.util.Scanner;
3: public class BadRequests {
5: public static void main(String[] args) {
6: // create list of Students
7: Student jake = new Student("Jake");
8: Student angie = new Student("Angie");
9: Student geety = new Student("Geety");
10:
11: // add grades to students and students to list
12: jake.setAsgnGrades(new int[]{75, 65});
13: angie.setAsgnGrades(new int[]{55, 65});
14: geety.setAsgnGrades(new int[]{95, 85});
15: Student.releaseAssignment(2);
17: // print student reports
18: System.out.println("Here are our students:");
19: jake.printReport();
20: pause();
21: angie.printReport();
22: pause();
23: geety.printReport();
24: pause();
26: // try to revise grade to illegal value
27: try {
28: System.out.println("Trying to change Jake's A1 grade to -10...");
29: jake.setAsgnGrade(1, -10);
30: System.out.println("...it WORKED?!?");
31: } catch (InvalidGradeException ige) {
32: System.out.println("... failed because " + ige);
33: } catch (NoSuchAssignmentException iae) {
34: System.out.println("... failed because " + iae);
35: }
36: pause();
38: // try to revise grade to legal value
39: try {
40: System.out.println("Trying to change Angie's A1 grade to 80...");
41: angie.setAsgnGrade(1, 80);
42: System.out.println("...it WORKED!");
43: } catch (InvalidGradeException ige) {
44: System.out.println("... failed because " + ige);
45: } catch (NoSuchAssignmentException iae) {
46: System.out.println("... failed because " + iae);
47: }
48: pause();
50: // try to revise grade to illegal value
51: try {
52: System.out.println("Trying to change Geety's A0 grade to 90...");
53: jake.setAsgnGrade(0, 90);
54: System.out.println("...it WORKED?!?");
55: } catch (InvalidGradeException ige) {
56: System.out.println(".. failed because " + ige);
57: } catch (NoSuchAssignmentException iae) {
58: System.out.println("... failed because " + iae);
59: }
60: pause();
62: // print student reports
63: System.out.println("Here are our students:");
64: jake.printReport();
65: pause();
66: angie.printReport();
67: pause();
68: geety.printReport();
69: pause();
70: }
72: /**
73: * Prompt the user and wait for them to press the enter key.
74: * Start prompt on a new line.
75: * Leave a blank line after the prompt/response.
76: */
77: private static void pause() {
78: Scanner kbd = new Scanner(System.in);
79: System.out.print("\nPress enter...");
80: kbd.nextLine();
81: System.out.println();
82: }
83: }