编写学生(Student)类,在主类中赋值并输出学生相关信息;编写教师(Teacher)类,在主类中赋值并输出教师相关信息。
class Studentss {
private int iNO; //封装学号属性,使用private关键字
private String iName; //封装姓名属性,使用private关键字
private float iScore; //封装成绩属性,使用private关键字
//构造函数,为属性赋值
public Studentss(int NO, String Name, int Score) {
this.iNO = NO;
this.iName = Name;
this.iScore = Score;
}
//通过对外接口访问内部属性
public int getiNO() {
return iNO;
}
public String getiName() {
return iName;
}
public float getiScore() {
return iScore;
}
}
public class Teacherss {
static final int STU_NUM = 5; //static关键字,静态成员
static float[] arrScore = new float[STU_NUM];
public static void main(String[] args) {
//创建五个实例
Studentss[] date = new Studentss[STU_NUM];
date[0] = new Studentss(1, "ling", 90);
date[1] = new Studentss(2, "hui", 40);
date[2] = new Studentss(3, "he", 59);
date[3] = new Studentss(4, "ze", 100);
date[4] = new Studentss(5, "xi", 95);
//将成绩存储到arrScore数组中
for(int i = 0; i < arrScore.length; i ++)
arrScore[i] = date[i].getiScore();
//遍历实例数组,打印信息
System.out.println("学生信息如下:");
for(int i = 0; i < date.length; i ++) {
System.out.print(date[i].getiNO() + " ");
System.out.print(date[i].getiName() + " ");
System.out.println(date[i].getiScore());
}
}
自己的作业最好是自己做哦