mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-17 04:51:58 -05:00
40 lines
925 B
Java
40 lines
925 B
Java
package com.study.demo2;
|
|
|
|
public class Student {
|
|
private String id;
|
|
private String name;
|
|
private int[] score = new int[10];
|
|
|
|
public Student(String id, String name, int[] scores) {
|
|
this.id = id;
|
|
this.name = name;
|
|
if (scores.length == 10) {
|
|
this.score = scores;
|
|
}
|
|
}
|
|
|
|
public double getAverage() {
|
|
int sum = 0;
|
|
for (int s : score) {
|
|
sum += s;
|
|
}
|
|
return (double) Math.round((sum / 10.0) * 100) / 100;
|
|
}
|
|
|
|
public int getMaxScore() {
|
|
int max = score[0];
|
|
for (int s : score) {
|
|
if (s > max) max = s;
|
|
}
|
|
return max;
|
|
}
|
|
|
|
public char getGrade() {
|
|
double avg = getAverage();
|
|
if (avg >= 90) return 'A';
|
|
else if (avg >= 80) return 'B';
|
|
else if (avg >= 70) return 'C';
|
|
else if (avg >= 60) return 'D';
|
|
else return 'E';
|
|
}
|
|
} |