forked from safesit23/JavaLabExercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentScores.java
More file actions
49 lines (46 loc) · 1.43 KB
/
Copy pathStudentScores.java
File metadata and controls
49 lines (46 loc) · 1.43 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
package Array;
import java.util.Arrays;
import java.util.Scanner;
public class StudentScores {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numOfSt,i;
System.out.print("Enter the num of student: ");
numOfSt = input.nextInt();
int[] student = new int[numOfSt];
System.out.print("Enter "+numOfSt+" scores: ");
for(i=0;i<numOfSt;i++){
student[i] = input.nextInt();
}
//Find highest
int highestScore = highestScore(student);
//Show Info and grade
for(i=0;i<numOfSt;i++){
System.out.println("Student "+(i+1)+" score is "+student[i]+" and grade is "+studentGrade(student,i,highestScore));
}
}
public static char studentGrade(int[] student,int i,int hs){
char grade;
if(student[i]>=hs-10){
grade = 'A';
}else if(student[i]>=hs-20){
grade = 'B';
}else if(student[i]>=hs-30){
grade = 'C';
}else if(student[i]>=hs-40){
grade = 'D';
}else{
grade = 'F';
}
return grade;
}
public static int highestScore(int[] student){
int hs=student[0];
for(int i=0;i<student.length;i++){
if(student[i]>hs){
hs=student[i];
}
}
return hs;
}
}