// A program to calculate a student's overall grade in a course // somewhat similar to CSE142. // // 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) { double hwPct = calcHwScore(hw1, hw1Poss, hw2, hw2Poss, hw3, hw3Poss, hw4, hw4Poss); int mid = 87; int fin = 80; double overall = calcOverallPct(hwPct, mid, fin); printResults(hwPct, mid, fin, overall); } // Computes and return a student's homework score. // // int score1 - the students score on HW1 // int poss1 - the maximum possible score on HW1 // int score2 - the students score on HW2 // int poss2 - the maximum possible score on HW2 // int score3 - the students score on HW3 // int poss3 - the maximum possible score on HW3 // int score4 - the students score on HW4 // int poss4 - the maximum possible score on HW4 public static double calcHwScore(int score1, int poss1, int score2, int poss2, int score3, int poss3, int score4, int poss4) { int totalScore = score1 + score2 + score3 + score4; int totalPoss = poss1 + poss2 + poss3 + poss4; return (double) totalScore / totalPoss; } // Computes and returns a student's overall grade in the course // using the formula: 45% homework, 20% midterm, 35% final // // double hwPct - student's homework 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 calcOverallPct(double hwPct, int mid, int fin) { double overall = (hwPct * 0.45) + (mid / 100.0 * 0.20) + (fin / 100.0 * 0.35); return overall; } // Prints the parts of a student's grade in the course // // double hwPct - student's homework 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 hwPct, int mid, int fin, double overall) { System.out.println("HW Avg: " + hwPct * 100.0); System.out.println("Midterm: " + mid); System.out.println("Final: " + fin); System.out.println("OVERALL: " + overall * 100.0); } }