Advertisement
SX514LEFV

Grade Calculator Programming 1

Oct 7th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. public class GradeCalculator{
  2.     public static double calculateAssignment(double asst1, double asst2, double asst3){
  3.         double avgasst = (asst1 + asst2 + asst3)/3;
  4.         //calculating the average of the assignment grades by adding them all up and dividing by the number of grades
  5.         return avgasst;
  6.         //I'm going to need my assignment average later so I'm returning the new value
  7.     }
  8.     public static double calculateQuiz(double quiz1, double quiz2, double quiz3){
  9.         double minquiz = Math.min(quiz1, Math.min(quiz2, quiz3));
  10.         //to find the smallest of 3 numbers, I set up mathmin so that it first finds which is the lowest grade between quiz 2 and 3, and then compares this lowest value with quiz 1
  11.         double avgquiz = (quiz1 + quiz2 + quiz3 - minquiz)/2;
  12.         //because I don't know beforehand which quiz will have the lowest grade, I'm subtracting the minquiz double to nullify the value of the lowest grade, before dividing the sum by 2 to get the average
  13.         return avgquiz;
  14.     }
  15.     public static double calculateTotal(double avgasst, double avgquiz, double midterm, double finals){
  16.         //to find the weighed average I'm going to multiply the average of each grade type by the percentage of the final grade it will account for
  17.         double weighedasst = avgasst * 30/100;
  18.         //because assignments are worth 30%, I multiply the grade by 30 and divide by 100
  19.         double weighedmidterm = midterm * 25/100;
  20.         //same thing but for 25% of final grade
  21.         double weighedfinal = finals * 40/100;
  22.         double weighedquiz = avgquiz * 5/100;
  23.         double weighedaverage = weighedasst + weighedmidterm + weighedfinal + weighedquiz;
  24.         //because I've found how many points each average is worth already, I just have to add them to find the total weighted average
  25.         return weighedaverage;
  26.     }
  27.     public static void calculateGrade(){
  28.         java.util.Scanner reader = new java.util.Scanner(System.in);
  29.         System.out.println("Input grade of assignment 1:");
  30.         double asst1 = reader.nextDouble();
  31.         System.out.println("Input grade of assignment 2:");
  32.         double asst2 = reader.nextDouble();
  33.         System.out.println("Input grade of assignment 3:");
  34.         double asst3 = reader.nextDouble();
  35.         // here I am prompting the user to give me the input for the assignment grades and then scanning the input to put into double variables
  36.         double avgasst = calculateAssignment(asst1, asst2, asst3);
  37.         //calling on the calculateAssignment method where I will calculate the average of the three assignments
  38.         System.out.println("Input grade of quiz 1:");
  39.         double quiz1 = reader.nextDouble();
  40.         System.out.println("Input grade of quiz 2:");
  41.         double quiz2 = reader.nextDouble();
  42.         System.out.println("Input grade of quiz 3:");
  43.         double quiz3 = reader.nextDouble();
  44.         //received input for quiz grades
  45.         double avgquiz = calculateQuiz(quiz1, quiz2, quiz3);
  46.         //going to calculateQuiz method to find the quiz average
  47.         System.out.println("Input grade on the midterm:");
  48.         double midterm = reader.nextDouble();
  49.         System.out.println("Input grade on the final:");
  50.         double finals = reader.nextDouble();
  51.         double weightedaverage = calculateTotal(avgasst, avgquiz, midterm, finals);
  52.         //calling on the calculateTotal method to find weighted average
  53.         System.out.println("Your assignment average is: " +avgasst);
  54.         System.out.println("Your quiz average (after dropping the lowest grade) is: " +avgquiz);
  55.         System.out.println("Your weighted average is: " +weightedaverage);
  56.         double finalgrade = Math.max(weightedaverage, finals);
  57.         //comparing weighed average to the grade on the final to find the highest
  58.         System.out.println("Your final grade is: " +finalgrade);
  59.         //printing the highest of the two
  60.     }
  61.     public static void main(String[]args){
  62.         calculateGrade();
  63.         //calling my grade calculating method from main
  64.     }
  65. }      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement