I want to make sure I am doing this programming assignment the right way.
Question:
Your history instructor gives three tests worth 50 points each. You can drop one of the first two grades. Your final grade is the sum of the best of the first two grades and the third grade. Given three test grades, write a program that calculates the final letter grade using the following cut-off points. The output should list all three test grades, state what test was dropped and the final letter grade. >= 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 to format 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 final letter grade is C.
My Code
package javaapplication28; import java.util.Scanner; public class JavaApplication28 { public static void main(String[] args) { double firstTest, secondTest, thirdTest; double sum; Scanner keyboard = new Scanner (System.in); System.out.print("First Test: "); firstTest = keyboard.nextDouble(); System.out.print("Second Test: "); secondTest = keyboard.nextDouble(); System.out.print("Third Test: "); thirdTest = keyboard.nextDouble(); if( firstTest > secondTest) { sum = firstTest + thirdTest; System.out.println("\nFirst Test: " + firstTest); System.out.println("Second Test: " + secondTest); System.out.println("Third Test: " + thirdTest); System.out.print("\nAfter dropping test 2, The final grade is " + sum + "." + "\n"); } else if( secondTest > firstTest) { sum = secondTest + thirdTest; System.out.println("\nFirst Test: " + firstTest); System.out.println("Second Test: " + secondTest); System.out.println("Third Test: " + thirdTest); System.out.print("\nAfter dropping test 1, The final grade is " + sum + "." + "\n"); } System.exit(0); } }