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

1. Write a class and a tester that reads students scores, gets the best score an

ID: 3663737 • Letter: 1

Question

1. Write a class and a tester that reads students scores, gets the best score and then assign 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 for 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: Enter the number of students: 4 Enter 4 scores: 40 55 70 58 Student 1 is 40 and grade is C. Student 2 is 55 and grade is B. Student 3 is 70 and grade is A. Student 4 is 58 and grade is B. Instance Fields: Array of scores, Best grade Methods: public void add (double score) public String findBestGrade( ) public String findStudentGrade( )

Explanation / Answer

Program:

import java.util.Scanner;
public class Grades {
   private static Scanner sca;
   public static void main(String str[])
   {
       int num;
       char grade;
       sca = new Scanner(System.in);
       System.out.println("Enter number of students : ");
       num=sca.nextInt();
       int[] arrayOfScore=new int[num];
       for(int i=0;i<num;i++)
       {
           System.out.print(" Enter Score of Student "+(i+1)+" : ");
           arrayOfScore[i]=sca.nextInt();
       }  
       int best=arrayOfScore[0];
       for(int i=1;i<num;i++)
       {
           if(arrayOfScore[i]>best)
               best=arrayOfScore[i];
       }
       for(int i=0;i<num;i++)
       {
           if(arrayOfScore[i]>=(best-10))
               grade='A';
           else if(arrayOfScore[i]>=(best-20))
               grade='B';
           else if(arrayOfScore[i]>=(best-30))
               grade='C';
           else if(arrayOfScore[i]>=(best-40))
               grade='D';
           else
               grade='F';
           System.out.print(" Studen "+(i+1)+" is "+arrayOfScore[i]+" and grade is "+grade);
       }
   }
  
}

Result:

Enter number of students :
4

Enter Score of Student 1 : 40

Enter Score of Student 2 : 55

Enter Score of Student 3 : 70

Enter Score of Student 4 : 58

Studen 1 is 40 and grade is C
Studen 2 is 55 and grade is B
Studen 3 is 70 and grade is A
Studen 4 is 58 and grade is B

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote