Grade is A if score is >= best - 10; Grade is B if score is >= best - 20; Grade
ID: 3619998 • Letter: G
Question
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 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:
Enter the number of students: [4] (enter)
Enter [4] scores: 40 55 70 58 (enter)
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
Explanation / Answer
Hope this helps,
please rate LifeSaver!
import java.util.ArrayList;
import java.util.Scanner;
public class studentScores {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of students");
int num = sc.nextInt();
ArrayList<Integer>scores = new ArrayList<Integer>();
System.out.println("Enter "+num+" scores");
for(int i =0;i<num;i++){
scores.add(sc.nextInt());
}
//used to sort the scores list
for(int i = 1; i < scores.size(); ++i){
for(int j = i; j >= 1; --j){
if(scores.get(j-1) > scores.get(j))
{
int temp =scores.get(j);
scores.set(j, scores.get(j-1));
scores.set(j-1, temp);
}
else
break;
}
}
int a = scores.get(scores.size()-1)-10;
int b = scores.get(scores.size()-1)-20;
int c = scores.get(scores.size()-1)-30;
int d = scores.get(scores.size()-1)-40;
for(int i =0; i<scores.size();i++){
if(scores.get(i)>=a){
System.out.println("Student "+i+" score is "+scores.get(i)+" and grade is A");
}
else if(scores.get(i)<a && scores.get(i)>=b){
System.out.println("Student "+i+" score is "+scores.get(i)+" and grade is B");
}
else if(scores.get(i)<b && scores.get(i)>=c){
System.out.println("Student "+i+" score is "+scores.get(i)+" and grade is C");
}
else if(scores.get(i)<c && scores.get(i)>=d){
System.out.println("Student "+i+" score is "+scores.get(i)+" and grade is D");
}
else if(scores.get(i)<d){
System.out.println("Student "+i+" score is "+scores.get(i)+" and grade is F");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.