6.1 JAVA ( DO NOT COPY CODE FROM ANOTHER WEBSITE) (Assign grades) Write a progra
ID: 3694151 • Letter: 6
Question
6.1 JAVA ( DO NOT COPY CODE FROM ANOTHER WEBSITE)
(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 Grade is B if score is best ; Grade is C if score is best ; Grade is D if score is best ; 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.*;
import java.io.*;
public class Grades
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
int stu_no = 0;
int classScore = 0;
String grades = " ";
int bestScore = 0;
System.out.print("enter the number of students: ");
int n = scan.nextInt();
int []classSize = new int [n];
System.out.print("Enter the " + n + " scores: ");
for (int i = 0; i < n; i++)
classSize[i] = scan.nextInt();
//end for
if ( classScore > bestScore )
bestScore = classScore;
for ( int i = 0; i < n; i++)
if ( classSize[i] >= bestScore -10)
grades = "A" ;
else if (classSize[i] >= bestScore - 20)
grades = "B";
else if (classSize[i] >= bestScore - 30)
grades = "C";
else if (classSize[i] >= bestScore - 40)
grades = "D";
else
grades = "F";
System.out.println("Student " + classSize[i] + " is " + bestScore + " and grade is " + grades);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.