5.9k views
5 votes
Create a Java program that asks the user for three test

scores. The program should display the average of the
test scores, and the letter grade (A, B, C, D or F) that
corresponds to the numerical average. (use dialog boxes
for input/output)

User Tonys
by
6.9k points

1 Answer

3 votes

Answer:

there aren't many points so it's not really worth it but here

kotlin

Copy code

import javax.swing.JOptionPane;

public class TestScoreGrader {

public static void main(String[] args) {

double score1, score2, score3, average;

String input, output;

input = JOptionPane.showInputDialog("Enter score 1: ");

score1 = Double.parseDouble(input);

input = JOptionPane.showInputDialog("Enter score 2: ");

score2 = Double.parseDouble(input);

input = JOptionPane.showInputDialog("Enter score 3: ");

score3 = Double.parseDouble(input);

average = (score1 + score2 + score3) / 3;

output = "The average is " + average + "\\";

output += "The letter grade is " + getLetterGrade(average);

JOptionPane.showMessageDialog(null, output);

}

public static char getLetterGrade(double average) {

if (average >= 90) {

return 'A';

} else if (average >= 80) {

return 'B';

} else if (average >= 70) {

return 'C';

} else if (average >= 60) {

return 'D';

} else {

return 'F';

}

}

}

Step-by-step explanation:

User Shekwi
by
7.5k points