// Miya Natsuhara // 07-10-2019 // CSE142 // TA: Grace Hopper // Calculates the overall percentage for a student in a course. /* DEVELOPMENT NOTES: ((Note: this is not something you should include in your own programs; this is included here to aid in your understanding and to provide additional context for the program.)) This was another good use of parameters and returns to improve *information flow* in our program (how data is stored and passed around to / returned from different methods). Note that we could have achieved the same behavior by having all of this code in main, but that would violate our rule of ensuring that main is a concise summary of the program. */ public class Grades { public static void main(String[] args) { // 45% homeworks (4), 20% midterm, 35% final // want to calculate the overall percentage in the class // get homework percentage double hwPct = calcHwPct(8, 10, 14, 16, 17, 20, 20, 20); System.out.println("homework percent: " + hwPct); // get midterm score int midtermScore = 89; // get final score int finalScore = 85; // calculate, print out overall percentage double overallPct = calcOverallGrade(hwPct, midtermScore, finalScore); System.out.println("overall percentage is: " + overallPct); } // Computes and returns a student's homework score give their scores on the individual // homeworks. // int score1: student's score on hw1 // int poss1: possible points on hw1 // int score2: student's score on hw2 // int poss2: possible points on hw2 // int score3: student's score on hw3 // int poss3: possible points on hw3 // int score4: student's score on hw4 // int poss4: possible points on hw4 public static double calcHwPct(int score1, int poss1, int score2, int poss2, int score3, int poss3, int score4, int poss4) { int sumActual = score1 + score2 + score3 + score4; int sumPossible = poss1 + poss2 + poss3 + poss4; double resultPct = (double) sumActual / sumPossible; return resultPct; } // Computes and returns a student's overall grade in the course where 45% of their grade is // based on their homework score, 20% of their grade is based on their midterm score, and 35% // of their grade based on their final score. // double hwPct: student's homework percentage // int midScore: student's score on midterm // int finScore: student's score on final public static double calcOverallGrade(double hwPct, int midScore, int finScore) { double midPct = midScore / 100.0; double finPct = finScore / 100.0; double overallScore = hwPct * 0.45 + midPct * 0.2 + finPct * 0.35; return overallScore; } }