Question: Write a program that reads student scores, gets the best score, and then assigns grades based on the following scheme:
The grade is A if the score is ≥ best −10;
The grade is B if the score is ≥ best −20;
The grade is C if the score is ≥ best −30;
The grade is D if the score is ≥ best −40;
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.

```package Array;

import java.util.Scanner;

/**
*Chapter 7 Exercise 1:
*
*      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
* Created by aarushi on 7/5/21.
*/

/*
Step 1: Ask user to input number of students (n)
Step 2: Create an array for grades and an array for scores
Step 3: Write a method that gets the best score
Step 4: Write a method that assigns grades
*/
public class Ch7Ex1 {

public static void main (String [] args){
//create scanner object
Scanner sc= new Scanner(System.in);
//declare variables to store the number of students and the best score
int numOfStudents, bestScore;

//input the number of students
System.out.print("Enter number of students: ");
numOfStudents= sc.nextInt();

//create one array to store the scores and another to store the grades
int [] scores= new int[numOfStudents];
char [] grades = new char[numOfStudents];

//Input the scores
System.out.println("Enter scores: ");
for (int i=0; i<numOfStudents; i++){
scores[i]= sc.nextInt();
}

bestScore= getBestScore(scores, numOfStudents);
System.out.println("Best Score: " + bestScore);

}

//function to get best score
public static int getBestScore (int [] scores, int size){
int bestScore = scores;

for (int i=0; i<size; i++){
if (scores[i]>bestScore){
bestScore= scores[i];
}
}

return bestScore;
}

//function to assign grades to students based on the best score
public static void assignGrades (int [] scores, char [] grades, int size, int bestScore){
for (int i=0; i<size; i++){
if (scores[i]>=(bestScore-10))
else if (scores[i]>=(bestScore-20))
else if (scores[i]>=(bestScore-30))
else if (scores[i]>=(bestScore-40))
else
}
}

//function to display array
public static void displayArray (int [] scores, char [] grades, int size){
for (int i=0; i<size; i++){
System.out.println("Student " + (i+1) + " Score: " + scores[i] + " Grade: " + grades[i]);
}
}
}
```
Java Programs

This site uses Akismet to reduce spam. Learn how your comment data is processed.