java考试成绩_编写一个java程序来计算学生考试成绩的平均分和他们的分数等级。你可以假设以下数据:...

展开全部

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值