-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise07_01.java
More file actions
54 lines (45 loc) · 1.58 KB
/
Copy pathExercise07_01.java
File metadata and controls
54 lines (45 loc) · 1.58 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
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jorda
*/
public class Exercise07_01 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numStudents = input.nextInt();
double[] grades = new double[numStudents];
double best = 0;
System.out.print("Enter four scores seperated by spaces or returns: ");
//assign grades
//find the best grade
for (int i = 0; i < numStudents; i++) {
grades[i] = input.nextDouble();
if (grades[i]>best)
best=grades[i];
}
//assign letter grades
char[] letterGrade = new char[numStudents];
for (int i = 0; i < numStudents; i++) {
if(grades[i]>=best-10)
letterGrade[i] = 'A';
else if(grades[i]>=best-20)
letterGrade[i] = 'B';
else if(grades[i]>=best-30)
letterGrade[i] = 'C';
else if(grades[i]>=best-40)
letterGrade[i] = 'D';
else
letterGrade[i] = 'F';
}
//print everything
for (int i = 0; i < numStudents; i++) {
System.out.println("Student " + i + " score is " + grades[i] + " and grade is " + letterGrade[i]);
}
}
}