// 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) { int hw1 = 10; int hw1Poss = 10; int hw2 = 15; int hw2Poss = 16; int hw3 = 18; int hw3Poss = 20; int hw4 = 15; int hw4Poss = 20; int totalScore = hw1 + hw2 + hw3 + hw4; int totalPoss = hw1Poss + hw2Poss + hw3Poss + hw4Poss; double hwPct = (double) totalScore / totalPoss; int mid = 87; int fin = 80; double overall = calcOverallPct(hwPct, mid, fin); printResults(hwPct, mid, fin, overall); } // 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); } }