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: 3568492 • 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 a best greater than equal to 10 Grade is B if score is a greater than equal to best - 20; Grade is C if score is greater than equal to best - 30; Grade is D if score is greater than equal to 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:

Explanation / Answer

import java.util.Scanner;


public class AssignGrade {
  
   public static void main(String[] args) {
      
       //Create Scanner to read input
       Scanner input = new Scanner(System.in);
      
       //Get number of students
       System.out.print("Enter the number of students: ");
       int numberOfStudents = input.nextInt();
       System.out.println();
      
       int[] scores = new int[numberOfStudents]; //Array for holding scores
       int bestScore = 0;
      
       //Get the students score and determine the best
       for (int i = 0; i < numberOfStudents; i++)
       {
           System.out.print("Please enter a score: ");
           scores[i] = input.nextInt();
          
           if (scores [i] > bestScore)
               bestScore = scores[i];
       }
      
       String output = ""; //String to be printed
       char grade; //Grade for the student
      
       //Determine the grade of each student
       for (int i = 0; i < numberOfStudents; i++)
       {
           if (scores[i] >= bestScore - 10)
               grade = 'A';
           else if (scores[i] >= bestScore - 20)
               grade = 'B';
           else if (scores[i] >= bestScore - 30)
               grade = 'C';
           else if (scores[i] >= bestScore - 40)
               grade = 'D';
           else
               grade = 'F';
          
           output += "Student "+i+" score is "+scores[i]+" and grade is "+grade+" ";
       }
      
       //Print the grade
       System.out.println(output);
      
      
   }

}