public class DemoClassStu {
public int id;
public String name;
public int age;
public int score;
public void showInfo(){
System.out.println(id+"\t"+name+"\t"+age+"\t"+score);
}
}
public class DemoClassStuInital {
DemoClassStu[] demoClassStus=new DemoClassStu[3];
public void addStu(DemoClassStu demoClassStu){
for (int i = 0; i < demoClassStus.length; i++) {
if (demoClassStus[i]==null){
demoClassStus[i]=demoClassStu;
return;
}
}
}
public void showAll(){
System.out.print("本班学生列表:\n");
for (int i = 0; i < demoClassStus.length; i++) {
if (demoClassStus[i]!=null){
demoClassStus[i].showInfo();
}
}
System.out.println();
}
}
public class DemoClassStuTest {
public static void main(String[] args) {
DemoClassStu demoClassStu=new DemoClassStu();
demoClassStu.id=1;
demoClassStu.name="测试";
demoClassStu.age=18;
demoClassStu.score=99;
DemoClassStu demoClassStu1=new DemoClassStu();
demoClassStu1.id=2;
demoClassStu1.name="测试1";
demoClassStu1.age=75;
demoClassStu1.score=9;
DemoClassStuInital demoClassStuInital=new DemoClassStuInital();
demoClassStuInital.addStu(demoClassStu);
demoClassStuInital.addStu(demoClassStu1);
demoClassStuInital.showAll();
}
}