update:demo2

This commit is contained in:
dichgrem
2025-10-31 17:01:12 +08:00
parent af1ea3e24e
commit d765c1a219
8 changed files with 214 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
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';
}
}