Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Assign grades ) Write a program that reads student scores, gets the best score,

ID: 3692772 • Letter: #

Question

(Assign grades ) Write a program that reads student scores, gets the best score, and

then assigns grades based on the following scheme:

Grade is A if score is >= best - 10;

Grade is B if score is >= best - 20;

Grade is C if score is >= best -30;

Grade is D if score is >= best -40;

Grade is F otherwise.

The program prompts the user to enter the total number of students, then prompts

the user to enter all of the scores, and concludes by displaying the grades. Here is

a sample run:

7= - 40

7= - 30

7= - 20

7= - 10

Enter the number of students: 4

Enter 4 scores: 45 50 70 58 (Enter)

Student 0 score is 40 and grade is C

Student 1 score is 55 and grade is B

Student 2 score is 70 and grade is A

Student 3 score is 58 and grade is B

Java Code!

Explanation / Answer

import java.util.Scanner;
public class Grade
{
public static void main(String[] args)
{
System.out.print("Enter the number of students:");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] score = new int[n];
int bestScore = 0;
System.out.print("Enter " + n + " scores:");
for (int i = 0; i < score.length; i++)
{
score[i] = input.nextInt();
if (bestScore < score[i])
{
bestScore = score[i];
}
}
char grade;
for (int i = 0; i < score.length; i++)
{
if (score[i] >= bestScore - 10)
grade = 'A';
else if (score[i] >= bestScore - 20)
grade = 'B';
else if (score[i] >= bestScore - 30)
grade = 'C';
else if (score[i] >= bestScore - 40)
grade = 'D';
else
grade = 'F';
System.out.println("Student " + i +" score is " + score[i] +" and grade is " + grade);
}
}
}