-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrading.java
More file actions
56 lines (48 loc) · 1.69 KB
/
Copy pathGrading.java
File metadata and controls
56 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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 >= 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.
*/
import java.util.Scanner;
public class Grading {
// Line offered by Eclipse to fix the low warinng for input
private static Scanner input;
public static void main(String[] args) {
// Create Scanner and request user input
input = new Scanner(System.in);
System.out.print("Enter the number of student: ");
int numberStudents = input.nextInt();
int [] scores = new int[numberStudents];
int best = 0;
char grade;
System.out.print("Enter " + numberStudents + "scores: ");
for (int i = 0; i < scores.length; i++) {
scores[i] = input.nextInt();
if (best < scores[i]) {
best = scores[i];
}
}
// Calculate grade from a set of given grades
char[] setGrade = {'A', 'B', 'C', 'D', 'F'};
for (int i = 0; i < scores.length; i++){
if (scores[i] >= best -10)
grade = setGrade[0];
else if (scores[i] >= best -20)
grade = setGrade[1];
else if (scores[i] >= best -30)
grade = setGrade[2];
else if (scores[i] >= best -40)
grade = setGrade[3];
else
grade = setGrade[4];
// Print results
System.out.println("Student " + i + " score is " + scores[i] + " " + grade);
}
}
}