public class SpecialGradeCalculator
1: import java.util.Scanner;
3: /**
4: * Calculate course grade using special rules.
5: *
6: * If you failed both testing parts of the course (less than 50%) or if you
7: * blew off the programming part of the course (less than 30%), then you fail
8: * the course regardless of whether you got high enuf grades.
9: *
10: * NOTE: this is NOT the grading scheme for CSCI 1226!
11: *
12: * @author Mark Young (A00000000)
13: */
14: public class SpecialGradeCalculator {
15:
16: public static void main(String[] args) {
17: // create Scanner
18: Scanner kbd = new Scanner(System.in);
20: // create variables for weights
21: double asgnWeight = 25.0;
22: double labsWeight = 15.0;
23: double testWeight = 20.0;
24: double examWeight = 30.0;
25: double bestWeight = 10.0;
27: // create variables for scores
28: double asgnGrade, labsGrade, testGrade, examGrade, courseGrade,
29: bestTest;
31: // create variables for special fail rules
32: boolean passedCourse;
33: boolean failedMidterm, failedFinal, failedBothTests;
34: boolean blewOffLabs, blewOffAsgns, blewOffWork;
35:
36: // introduce yourself
37: System.out.println("\n"
38: + "Grade Calculator (Console) #1\n"
39: + "-----------------------------\n\n"
40: + "Enter your percentage grades when prompted.");
42: // pause
43: System.out.print("\n" + "Press enter to continue...");
44: kbd.nextLine();
45: System.out.println();
47: // get the components of the course grade
48: System.out.print("Assignments: ");
49: asgnGrade = kbd.nextDouble();
50: kbd.nextLine();
51: System.out.print("Labs: ");
52: labsGrade = kbd.nextDouble();
53: kbd.nextLine();
54: System.out.print("Tests: ");
55: testGrade = kbd.nextDouble();
56: kbd.nextLine();
57: System.out.print("Exam: ");
58: examGrade = kbd.nextDouble();
59: kbd.nextLine();
60: bestTest = Math.max(testGrade, examGrade);
61:
62: // pause
63: System.out.print("\n" + "Press enter to calculate your grade...");
64: kbd.nextLine();
65: System.out.println();
67: // calculate the course grade
68: courseGrade = (asgnWeight * asgnGrade
69: + labsWeight * labsGrade
70: + testWeight * testGrade
71: + examWeight * examGrade
72: + bestWeight * bestTest)
73: / 100.0;
75: // display the course grade to the user
76: System.out.println("Your course grade is " + courseGrade + ".");
78: // people with 50% or better normally pass ...
79: passedCourse = (courseGrade >= 50);
80:
81: // ... but might fail because of special rules
82: // (only people who got a passing grade need to be checked)
83: if (passedCourse) {
84: // check if special fail rule applies
85: failedMidterm = (testGrade < 50);
86: failedFinal = (examGrade < 50);
87: failedBothTests = failedMidterm && failedFinal;
88: blewOffLabs = (labsGrade < 30);
89: blewOffAsgns = (asgnGrade < 30);
90: blewOffWork = blewOffLabs && blewOffAsgns;
92: // if special fail rule applies, tell them so!
93: if (failedBothTests || blewOffWork) {
94: // alert to special fail and record student's failure
95: System.out.println();
96: System.out.println("Special fail rule!");
97: System.out.println();
98: passedCourse = false;
100: // report reason(s) for failure
101: System.out.println("You cannot proceed because you: ");
102: if (failedBothTests) {
103: System.out.println(" - failed both tests");
104: }
105: if (blewOffWork) {
106: System.out.println(" - did not achieve sufficient grades "
107: + "in your programming work");
108: }
109: }
110: }
112: // print final message
113: System.out.println();
114: if (passedCourse) {
115: System.out.println("Congratulations, you passed!");
116: } else {
117: System.out.println("Sorry, you failed. Better luck next time");
118: }
119:
120: // pause
121: System.out.print("\n" + "Press enter to quit the program...");
122: kbd.nextLine();
123: System.out.println();
124: }
126: }