public class TestStudent
2: import java.util.Scanner;
4: /**
5: * Check the Student class by creating some objects and manipulating them.
6: *
7: * @author Mark Young (A00000000)
8: */
9: public class TestStudent {
11: public static void main(String[] args) {
12: // create a couple of students
13: Scanner kbd = new Scanner(System.in);
14: Student s1 = new Student("A00000001", "Dent, Stu.", 95);
15: Student s2 = new Student("A00000002", "Tudiaunt, A.", 80);
17: // show info for first two students
18: System.out.println("\n"
19: + "One student's info:"
20: + "\n\tName: " + s1.getName()
21: + "\n\tNumber: " + s1.getANumber()
22: + "\n\tGrade: " + s1.getPctGrade());
23: System.out.println("\n"
24: + "Another student's info:"
25: + "\n\tName: " + s2.getName()
26: + "\n\tNumber: " + s2.getANumber()
27: + "\n\tGrade: " + s2.getPctGrade());
29: // pause
30: System.out.print("\nPress Enter...");
31: kbd.nextLine();
32: System.out.println();
34: // Change some info for s1
35: s1.setName("Dent, Stuart");
36: s2.setPctGrade(90);
38: // show revised information
39: System.out.println("Revised information for the first student:");
40: s1.printStudentRecord();
41: System.out.println("Revised information for the second student:");
42: s2.printStudentRecord();
44: // pause
45: System.out.print("\nPress Enter...");
46: kbd.nextLine();
47: System.out.println();
49: // prepare to get more student information
50: Student stu = null; // so no complaint about "not initialized"
51: String num, name;
52: int pct;
54: // read student numbers until user signals to quit
55: System.out.print("Enter student's A-# (or Q to quit): ");
56: num = kbd.nextLine();
57: while (!num.startsWith("Q")) {
59: // read student info
60: System.out.print("Enter student name: ");
61: name = kbd.nextLine();
62: System.out.print("Enter percent grade: ");
63: pct = kbd.nextInt();
64: kbd.nextLine();
66: // create and print student information
67: stu = new Student(num, name, pct);
68: System.out.println("\n"
69: + stu.getName() + " (" + stu.getANumber() + ") "
70: + "got " + stu.getPctGrade() + "%");
72: // get next student’s number
73: System.out.print("Enter student's A-# (or Q to quit): ");
74: num = kbd.nextLine();
75: }
77: // pause
78: System.out.print("\nPress Enter...");
79: kbd.nextLine();
80: System.out.println();
82: // report last student read
83: System.out.println("The last student you entered was " + stu.aNumber);
84: stu.printStudentRecord();
86: // pause
87: System.out.print("\nPress Enter...");
88: kbd.nextLine();
89: System.out.println();
90: }
92: }