// 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 pct = hwScore(10, 10, 14, 16, 17, 20, 15, 20); overallGrade(pct, 88, 81); } // 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 hwScore(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; double pct = (double)totalScore / totalPoss; return pct; } // Computes and prints a student's overall grade in the course // using the formula: 45% homework, 20% midterm, 35% final // // double hw - 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 void overallGrade(double hw, int mid, int fin) { double midPct = mid / 100.0; double finPct = fin / 100.0; double result = hw * 0.45 + midPct * 0.2 + finPct * 0.35; System.out.println("Your grade is " + result); } }