/*
* 1.某中学有若干学生(学生对象放在一个List中), 每个学生有一个姓名属性(String)、
* 班级名称属性(String)和考试成绩属性(double) 某次考试结束后,每个学生都获得了一个考试成绩。
* 遍历list集合,并把学生对象的属性打印出来
*/
分两个类
第一个:
public class xuesheng {
private String name;
private String banji;
private double chengji;
public xuesheng(String name, String banji, double chengji) {
this.name = name;
this.banji = banji;
this.chengji = chengji;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBanji() {
return banji;
}
public void setBanji(String banji) {
this.banji = banji;
}
public double getChengji() {
return chengji;
}
public void setChengji(double chengji) {
this.chengji = chengji;
}
}
第二个类:
public class text {
public static void main(String[] args) {
List li = new ArrayList();
xuesheng x1 = new xuesheng("老王", "一班", 60);
xuesheng x2 = new xuesheng("老李", "二班", 80);
xuesheng x3 = new xuesheng("小王", "三班", 70);
xuesheng x4 = new xuesheng("小李", "四班", 90);
li.add(x1);
li.add(x2);