public class Program {
public String toLetterGrade(double score) {
// Define scores and grades
double[] scores = {95.0, 90.0, 85.0, 80.0, 75.0, 70.0, 65.0, 60.0};
String[] grades = {"A+", "A", "B+", "B", "C+", "C", "D+", "D"};
// Iterate through scores and find the grade
int scores_length = scores.length;
for (int i = 0; i < scores_length; i++) {
if (score >= scores[i]) {
return grades[i];
}
}
return "F"; // Default grade if none of the scores match
}
public static void main(String[] args) {
Program program = new Program();
// Test the program with individual scores
System.out.println(program.toLetterGrade(95)); // A+
System.out.println(program.toLetterGrade(90)); // A
System.out.println(program.toLetterGrade(80)); // B
System.out.println(program.toLetterGrade(60)); // D
System.out.println(program.toLetterGrade(50)); // F
}
}
/*
run:
A+
A
B
D
F
*/