Question: Have my java program to be at least 3 functions to handle various calculations, with arguments passed and a value returned. import java.text.DecimalFormat; import java.util.Scanner;
Have my java program to be at least 3 functions to handle various calculations, with arguments passed and a value returned.
import java.text.DecimalFormat; import java.util.Scanner; public class Grades { public static void main(String[] args) { /* creates a new Scanner instance which points to the input stream passed as argument*/ Scanner scan = new Scanner(System.in); /* display the opening message*/ System.out.println("This program accepts your homework and two exam scores as input and computes your grade in the course."); /*Homework weight*/ System.out.print("Homework weight? "); double HW_Weight = scan.nextDouble(); /*exam 1 weight*/ System.out.print("Exam 1 weight? "); double Exam_1= scan.nextDouble(); /* weight*/ double Weights = (100 - (HW_Weight + Exam_1)); /* weights of homework and 2 Exam */ System.out.println("Using weights of " + HW_Weight + " " + Exam_1 + " " + Weights); /*display homework*/ System.out.println("Homework:"); /* number of homework assignments */ System.out.print("Number of assignments? "); int Assignments = scan.nextInt(); /* average homework grade*/ System.out.print("Average Homework grade? "); double Average_HW_Grade = scan.nextDouble(); /* number of late days */ System.out.print("Number of late days used? "); int Late = scan.nextInt(); /* number of labs attended */ System.out.print("Labs attended? "); int labs = scan.nextInt(); /*Assign variable homework points */ double HW = 0; /* Max homework points */ double Max_HW_Points = (((Assignments * 10) + (Assignments * 4))); /* If number of assignments is zero or less, it will be one point */ if(Assignments <= 0) { HW = 1; System.out.println("Total points = 1"); } else { /* If average homework grade is negative, will be mark a zero */ if(Average_HW_Grade < 0) { Average_HW_Grade = 0; } /* If average homework grade is more than 10, it can't be more than 10 so will therefore will be capped at 10. */ if(Average_HW_Grade > 10) { Average_HW_Grade = 10; } /*If the number of late day exceed the number of assignments, the grade will decreased by 10% */ else if(Late > Assignments / 2) { Average_HW_Grade = (0.9 * Average_HW_Grade); } /*total homework score*/ double HW_Score = (Average_HW_Grade * Assignments); /* If the number of late days total to zero, the program will give 5 more credits for the homework*/ if(Late == 0 && ((HW_Score + 5) <= 10 * Assignments)) { HW_Score += 5; } /* total lab score */ double Lab_Score = (4 * labs); /* total points of homework and lab */ double Score = (HW_Score + Lab_Score); System.out.println("Total points = " + Score + " / " + Max_HW_Points); /* Calculate the credit points for homework and lab */ HW = (Score / Max_HW_Points); } /* Score for the homework and lab */ double Weighted_HW_Score = (HW_Weight * HW); DecimalFormat Rounded_Weighted_HW_Score = new DecimalFormat("##.00"); System.out.println("Weighted score = " + Rounded_Weighted_HW_Score.format(Weighted_HW_Score)); /*display Exam 1 */ System.out.println("Exam 1:"); /* exam 1 */ System.out.print("Score? "); int Exam_1_Score = scan.nextInt(); /* Exam 1 curve */ System.out.print("Curve? "); int Exam_1_Curve = scan.nextInt(); /* If exam 1 score is zero or below, it will be a zero */ if(Exam_1_Score <= 0) Exam_1_Score = 0; /*If Exam is greater than 100, it will still be at 100 */ else if(Exam_1_Score > 100) Exam_1_Score = 100; /* Calculate exam 1 */ double Final_Exam_1_Score = Math.min(100, Exam_1_Score + Exam_1_Curve); /* Store the score in exam 1*/ double Full_Exam_1_Points = 100; System.out.println("Total points = " + Final_Exam_1_Score + " / " + Full_Exam_1_Points); /* Calculate exam 1*/ double Final_Exam_1_Points = (Final_Exam_1_Score / Full_Exam_1_Points); /* Calculate weighted exam 1 */ double Weighted_Exam_1_Score = (Exam_1 * Final_Exam_1_Points); DecimalFormat Rounded_Weighted_Exam_1_Score = new DecimalFormat("##.00"); System.out.println("Weighted score = " + Rounded_Weighted_Exam_1_Score.format(Weighted_Exam_1_Score)); /* display exam 2*/ System.out.println("Exam 2: "); /* exam 2*/ System.out.print("Score? "); int Exam_2_Score = scan.nextInt(); /* Take input for the curve in exam 2 */ System.out.print("Curve? "); int Exam_2_Curve = scan.nextInt(); /* If exam 2 is zero or below, it will be zero */ if(Exam_2_Score <= 0) Exam_2_Score = 0; /* If exam 2 is higher than 100, it will be at 100 */ else if(Exam_2_Score > 100) Exam_2_Score = 100; /* Calculate exam 2 */ double Final_Exam_2_Score = Math.min(100, Exam_2_Score + Exam_2_Curve); /* Store full attainable exam 2 score */ double Full_Exam_2_Points = 100; System.out.println("Total points = " + Final_Exam_2_Score + " / " + Full_Exam_2_Points); /* Calculate exam 2*/ double Final_Exam_2_Points = (Final_Exam_2_Score / Full_Exam_2_Points); /* Calculate exam 2 weighted score */ double Weighted_Exam_2_Score = (Weights * Final_Exam_2_Points); System.out.println("Weighted score = " + Weighted_Exam_2_Score); /* course grade */ double Course_Grade = Weighted_HW_Score + Weighted_Exam_1_Score + Weighted_Exam_2_Score; DecimalFormat Rounded_Course_Grade = new DecimalFormat("##.00"); System.out.println("Course grade = " + Rounded_Course_Grade.format(Course_Grade)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
