展开全部
public class Score {
// 记录学生的姓名
private String[]name;
// 记录分数62616964757a686964616fe59b9ee7ad9431333363356535
private int[][]fraction;
// 记录分数等级
private char[]grade;
// 存储数据
private void saveData() {
this.name = new String[] { "Johnson", "Aniston", "Cooper", "Gupta", "Blair" };
this.fraction = new int[][] { { 85, 83, 77, 91, 76 }, { 80, 90, 95, 93, 48 }, { 78, 81, 11, 90, 73 }, { 92, 83, 30, 69, 87 }, { 23, 45, 96, 38, 59 } };
this.grade = new char[this.name.length];
}
public Score() {
// 在构造函数中调用saveData存储数据。
this.saveData();
}
// 计算分数等级。传入一个分数,返回该分数的评分等级。
private char getGrade(int fraction) {
if (fraction > 100) {
// 100分的考卷分数居然超过了100,肯定和老师有交易,给你个X!
return 'X';
}
else if (fraction >= 85) {
return 'A';
}
else if (fraction >= 75) {
return 'B';
}
else if (fraction >= 65) {
return 'C';
}
else if (fraction >= 50) {
return 'D';
}
return 'F';
}
// 输出成绩/平均分/评分/班级平均分/班级评分
public void printScore() {
int average = 0;// 存储班级的平均分
for (int i = 0; i
System.out.print(this.name[i] + "\t");// 输入学生的名字(\t是输出制表符,相当于按一下Tab的效果)
int temp = 0;// 临时存储数据的变量
for (int x = 0; x
temp += this.fraction[i][x];
System.out.print(this.fraction[i][x] + "\t");
}
temp = temp / this.fraction[i].length;// 此时temp的值就是该学生的平均分
this.grade[i] = this.getGrade(temp);// 存入平均分
System.out.println("平均分:" + temp + "\t评价" + this.grade[i]);// 输出该学生的平均分和评价
average += temp;
}
average = average / this.name.length;
System.out.println("班级平均分:" + average + "\t班级评价" + this.getGrade(average));
}
public static void main(String[] args) {
new Score().printScore();
}
}
运行结果:
Johnson8583779176平均分:82评价B
Aniston8090959348平均分:81评价B
Cooper7881119073平均分:66评价C
Gupta9283306987平均分:72评价C
Blair2345963859平均分:52评价D
班级平均分:70班级评价C