Files
Java/com/study/demo2/Student.java
2025-11-21 15:20:01 +08:00

47 lines
852 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';
}
}