//Student
package zuoye;
public class Student {
private String name;
private int age;
private int score;
private String classNum;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getClassNum() {
return classNum;
}
public void setClassNum(String classNum) {
this.classNum = classNum;
}
public Student(String name, int age, int score, String classNum) {
super();
this.name = name;
this.age = age;
this.score = score;
this.classNum = classNum;
}
}
//List
package zuoye;
import java.util.ArrayList;
import java.util.List;
public class TestStudent {
public static void main(String[] args) {
List<Student> list=new ArrayList();
list.add(new Student("Tom",18,100,"class05"));
list.add(new Student("Jerry",22,70,"class04"));
list.add(new Student("Owen",25,90,"class04"));
list.add(new Student("Jim",30,80,"class04"));
list.add(new Student("Steve",28,66,"class04"));
list.add(new Student("Kevin",24,100,"class04"));
int sumage=0;
int sumscore=0;
for(Student s:list)
{
sumage+=s.getAge();
sumscore+=s.getScore();
}
System.out.println("平均年龄为:"+sumage/list.size());
System.out.println("平均成绩为:"+sumscore/list.size());
}
}
// 运行结果
平均年龄为:24
平均成绩为:84