Your history instructor gives three tests worth 50 pointseach. You can drop one
ID: 3614178 • Letter: Y
Question
Your history instructor gives three tests worth 50 pointseach. You can drop one of the firsttwo grades. Your final grade is the sum of the best of thefirst two grades and the
third grade. Given three test grades, write a program thatcalculates the final letter grade
using the following cut-off points. The output should listall three test grades, state what test
was dropped and the final letter grade. Be sure to start anew source file and name it
Lab4_Ex2.java.
>= 90 A
< 90, >= 80 B
< 80, >= 70 C
< 70, >= 60 D
< 60 F
For example, if your input is 45 15 25 (you do not need toformat the input), the output of
your program should be very similar to:
First test: 45
Second test: 15
Third test: 25
After dropping test 2, the final grade is 70. The finalletter
grade is C.
Explanation / Answer
import java.util.Scanner; public class Lab4_Ex2 { public static void getGrade(double one, double two,double three) { // THE CODE GOES HERE System.out.println("===================" ); System.out.println("First test: " + one); System.out.println("Second test: " + two); System.out.println("Third test: " + three); double score=0; if(one>= two) { score = one + three; System.out.print("Afterdropping test 2, the final score is " + score+". The final lettergrade is "); } else { score=two+three; System.out.print("Afterdropping test 1, the final score is " + score+". The final lettergrade is "); } if(score >=90) System.out.println("A"); else if((score=80)) System.out.println("B"); else if((score=70)) System.out.println("C"); else if((score=60)) System.out.println("D"); else System.out.println("F"); } public static void main(String[] argv){ Scanner sc = new Scanner(System.in); System.out.print("Enter score in firsttest:"); double System.out.print("Enter score in secondtest:"); double two = sc.nextDouble(); System.out.print("Enter score in thirdtest:"); double three = sc.nextDouble(); Lab4_Ex2.getGrade(one, two, three); }//end of main }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.