//Program to calculate a student’s letter-grade based on // the average of their best 2 test scores. //The minimum average for each letter grade: // A:90 B:80 C:65 D:50 // import javax.swing.*; public class SelectionExample { public static void main(String[] args) { //Constants: Grade Minimum Averages final int MINIMUM_A = 90; final int MINIMUM_B = 80; final int MINIMUM_C = 65; final int MINIMUM_D = 50; //Input three Test Scores String input; input = JOptionPane.showInputDialog(null, "1st Score?"); int score1 = Integer.parseInt(input); input = JOptionPane.showInputDialog(null, "2nd Score?"); int score2 = Integer.parseInt(input); input = JOptionPane.showInputDialog(null, "3rd Score?"); int score3 = Integer.parseInt(input); //Find the lowest of the three Test Scorescores int lowest = score1; if (score2 < lowest) lowest = score2; if (score3 < lowest) lowest = score3; //Find the average of the two highest scores double average = (score1 + score2 + score3 - lowest) / 2.0; //Calculate the Letter-Grade based on the average char grade = 'F'; if (average >= MINIMUM_D) grade = 'D'; if (average >= MINIMUM_C) grade = 'C'; if (average >= MINIMUM_B) grade = 'B'; if (average >= MINIMUM_A) grade = 'A'; //Display the three Test Scores and Letter-Grade String report = "Test Scores: " + score1 + ", " + score2 + ", " + score3 + " Average (best 2): " + average + " Letter Grade: " + grade; JOptionPane.showMessageDialog(null, report); } }