定义一个表示学生信息的类Student,要求如下:
(1)类Student的成员变量:
sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。
(2)类Student带参数的构造方法:
在构造方法中通过形参完成对成员变量的赋值操作。
(3)类Student的方法成员:
getNo():获得学号;
getName():获得姓名;
getSex():获得性别;
getAge()获得年龄;
getJava():获得Java 课程成绩
(4)根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值。
public class Student {
private double sNO;
private String sName;
private String sSex;
private int sAge;
private double sJava;
public Student(double sNO,String sName,String sSex,int sAge,double sJava) {
this.sAge = sAge;
this.sJava = sJava;
this.sName = sName;
this.sSex = sSex;
this.sNO = sNO;
}
public double getNO() {
return sNO;
}
public String getName() {
return sName;
}
public String getSex() {
return sSex;
}
public int getAge() {
return sAge;
}
public double getJava() {
return sJava;
}
public static void main(String args[]) {
Student s1 = new Student(1, "王", "男", 20, 100);
Student s2 = new Student(1, "李", "男", 20, 75);
Student s3 = new Student(1, "张", "男", 20, 85);
Student s4 = new Student(1, "周", "男", 20, 80);
Student s5 = new Student(1, "胡", "男", 20, 99);
double avg = (s1.getJava()+s2.getJava()+s3.getJava()+s4.getJava()+s5.getJava())/5.0;
System.out.println("五个同学的平均成绩为"+avg);
}
}