Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GradeCalculator{
- public static double calculateAssignment(double asst1, double asst2, double asst3){
- double avgasst = (asst1 + asst2 + asst3)/3;
- //calculating the average of the assignment grades by adding them all up and dividing by the number of grades
- return avgasst;
- //I'm going to need my assignment average later so I'm returning the new value
- }
- public static double calculateQuiz(double quiz1, double quiz2, double quiz3){
- double minquiz = Math.min(quiz1, Math.min(quiz2, quiz3));
- //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
- double avgquiz = (quiz1 + quiz2 + quiz3 - minquiz)/2;
- //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
- return avgquiz;
- }
- public static double calculateTotal(double avgasst, double avgquiz, double midterm, double finals){
- //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
- double weighedasst = avgasst * 30/100;
- //because assignments are worth 30%, I multiply the grade by 30 and divide by 100
- double weighedmidterm = midterm * 25/100;
- //same thing but for 25% of final grade
- double weighedfinal = finals * 40/100;
- double weighedquiz = avgquiz * 5/100;
- double weighedaverage = weighedasst + weighedmidterm + weighedfinal + weighedquiz;
- //because I've found how many points each average is worth already, I just have to add them to find the total weighted average
- return weighedaverage;
- }
- public static void calculateGrade(){
- java.util.Scanner reader = new java.util.Scanner(System.in);
- System.out.println("Input grade of assignment 1:");
- double asst1 = reader.nextDouble();
- System.out.println("Input grade of assignment 2:");
- double asst2 = reader.nextDouble();
- System.out.println("Input grade of assignment 3:");
- double asst3 = reader.nextDouble();
- // 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
- double avgasst = calculateAssignment(asst1, asst2, asst3);
- //calling on the calculateAssignment method where I will calculate the average of the three assignments
- System.out.println("Input grade of quiz 1:");
- double quiz1 = reader.nextDouble();
- System.out.println("Input grade of quiz 2:");
- double quiz2 = reader.nextDouble();
- System.out.println("Input grade of quiz 3:");
- double quiz3 = reader.nextDouble();
- //received input for quiz grades
- double avgquiz = calculateQuiz(quiz1, quiz2, quiz3);
- //going to calculateQuiz method to find the quiz average
- System.out.println("Input grade on the midterm:");
- double midterm = reader.nextDouble();
- System.out.println("Input grade on the final:");
- double finals = reader.nextDouble();
- double weightedaverage = calculateTotal(avgasst, avgquiz, midterm, finals);
- //calling on the calculateTotal method to find weighted average
- System.out.println("Your assignment average is: " +avgasst);
- System.out.println("Your quiz average (after dropping the lowest grade) is: " +avgquiz);
- System.out.println("Your weighted average is: " +weightedaverage);
- double finalgrade = Math.max(weightedaverage, finals);
- //comparing weighed average to the grade on the final to find the highest
- System.out.println("Your final grade is: " +finalgrade);
- //printing the highest of the two
- }
- public static void main(String[]args){
- calculateGrade();
- //calling my grade calculating method from main
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement