// A program to calculate a student's overall grade in a course // somewhat similar to CSE142. // // DEVELOPMENT NOTES: // (These notes would not be in your program's comments. They are here // to help you understand important topics or elements of this code.) // // Notice the use of parameters and return values to capture the // structure of the program while still allowing main to retain // high-level control. public class Grades { public static void main(String[] args) { int assign1Score = 10; int assign1Poss = 10; int assign2Score = 15; int assign2Poss = 16; int assign3Score = 19; int assign3Poss = 20; int midterm = 88; int fin = 82; double assignAvg = calculateAssignGrade(assign1Score, assign2Score, assign3Score, assign1Poss, assign2Poss, assign3Poss); double overall = calculateGrade(assignAvg, midterm, fin); printResults(assignAvg, midterm, fin, overall); printAchievements(assignAvg, midterm, fin, overall); } // Computes and returns a student's total programming assignment grade. // // int score1 - the student's score on A1 // int score2 - the student's score on A2 // int score3 - the student's score on A3 // int poss1 - the maximum possible score on HW1 // int poss2 - the maximum possible score on HW2 // int poss3 - the maximum possible score on HW3 public static double calculateAssignGrade(int score1, int score2, int score3, int poss1, int poss2, int poss3) { int assignTotal = score1 + score2 + score3; int assignPoss = poss1 + poss2 + poss3; double assignAvg = (double) assignTotal / assignPoss; return assignAvg; } // Computes and returns a student's overall grade in the course // using the formula: 45% assignments, 20% midterm, 35% final // // double assignAvg - student's programming assignment percentage // int mid - student's score on the midterm (out of 100) // int fin - student's score on the final exam (out of 100) public static double calculateGrade(double assignAvg, int midterm, int fin) { return (0.45 * assignAvg) + (0.20 * (midterm / 100.0)) + (0.35 * (fin / 100.0)); } // Prints the parts of a student's grade in the course // // double assigns - student's programming assignment percentage // int mid - student's score on the midterm (out of 100) // int fin - student's score on the final exam (out of 100) // double overall - student's overall percentage in the course public static void printResults(double assigns, int mid, int fin, double overall) { System.out.println("Assign. Average: " + assigns); System.out.println("Midterm: " + mid); System.out.println("Final: " + fin); System.out.println("Overall grade: " + overall); } // Prints various messages about a student's specific achievements in the course // // double assigns - student's programming assignment percentage // int mid - student's score on the midterm (out of 100) // int fin - student's score on the final exam (out of 100) // double overall - student's overall percentage in the course public static void printAchievements(double assigns, int mid, int fin, double overall) { if (assigns > 0.9) { System.out.println("Great job on your programming assignments!"); } System.out.println("Have a great quarter."); } }