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

Programming Exercise 7.1 Assign grades) Write a program that reads student score

ID: 3901379 • Letter: P

Question

Programming Exercise 7.1 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 2 best - 30 Grade is D if score is 2 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. SAMPLE RUN: Enter the number of students: 4 Enter 4 scores: 40 55 70 58 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 Class Name: Exercise07_01 If you get a logical or runtime error, please refer https:/liveexample.pearsoncmg.com/faq.html.

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

// declaring variables

int n, i;

Scanner sc = new Scanner(System.in);

// taking user input of number of scores

System.out.print("Enter the number of students: ");

n = sc.nextInt();

System.out.printf("Enter %d scores: ",n);

int[] scores = new int[n];

int best = 0;

// taking user input for scores

// updating the best score as well

for(i=0; i<n; i++)

{

scores[i] = sc.nextInt();

// updating best

if(best < scores[i])

best = scores[i];

}

// looping through each

score and printing grades

for(i=0; i<n; i++)

{

// printing grade

char grade = ' ';

if(scores[i] >= best - 10)

grade = 'A';

else if(scores[i] >= best - 20)

grade = 'B';

else if(scores[i] >= best - 30)

grade = 'C';

else if(scores[i] >= best - 40)

grade = 'D';

System.out.printf("Sutdent %d score is %d and grade is %c ",i,scores[i],grade);

}

}

}

/*SAMPLE OUTPUT

Enter the number of students: 4

Enter 4 scores: 40 55 70 58

Sutdent 0 score is 40 and grade is C

Sutdent 1 score is 55 and grade is B

Sutdent 2 score is 70 and grade is A

Sutdent 3 score is 58 and grade is B

*/