帮忙写一个JAVA小程序

来源:百度知道 编辑:UC知道 时间:2024/07/07 03:59:37
1. 定义一个表示学生的类Student。Student类包括表示学生的学号、姓名、性别、年龄和3门课程乘积的信息数据及用来获得和设置这些数据的方法。创建TestStudent类,在TestStudent类中生成5个学生对象,计算3门课的平均乘积,以及某门课程的最高分和最低分。
[解答] 解题思路
(1) 按照要求定义学生类,其中包括学生的学号、姓名、年龄和3门可策划那个成绩等成员变量,并定义各种获取和设置成员变量值的方法。
(2) 定义一个主类,在main()方法中意义5名学生对象,求出每门课程的平均乘积、最高分和最低分

public class Student {
private String sno;// 学号
private String sname;// 姓名
private String sex;// 性别
private Integer age;// 年龄
private Integer[] scores;// 三门课程成绩
//get、set方法自行补齐
}
/**
* 计算平均成绩,最高成绩和最低成绩
*
* @author yunfeiyang
* @version 1.0
* @since JDK1.5
*/
public class CountScore {

/**
* 计算某一门的平均成绩
*
* @param scores
* @return the avg_score
*/
public static int avg(int[] scores) {
if (scores.length == 0)
return 0;
int sum = 0;
for (int i : scores)
sum += i;
return sum / scores.length;
}

/**
* 计算某一门的最高成绩
*
* @param scores
* @return the max_score
*/
public static int max(int[] scores) {
if (scores.length == 0)
return 0;
int max_score = 0;
for (int i = 0; i < scores.length; i++) {
if (i == 0 || m