/学生类Student的定义
package ch09_02;
public class Student {
	private String sno;     //学生学号
	private String sname;   //姓名
	private int score;       //分数
	public Student(){}      //无参构造方法
	public Student(String sno, String sname, int score) { //有参构造方法
		this.sno = sno;this.sname = sname;this.score = score;
	}
	public String getSno() {return sno;}
	public void setSno(String sno) {this.sno = sno;	}
	public String getSname() {return sname;}
	public void setSname(String sname) {this.sname = sname;}
	public int getScore() {return score;}
	public void setScore(int score) {this.score = score;}
	public String toString() {  //重写Object中的toString()方法，将对象转换为字符串
		return "学号：" + sno + ",姓名：" + sname + ",分数：" + score;
	}
}

//主类的定义，在该类中实现对集合对象的数据添加、删除、修改以及遍历处理
package ch09_02;
import java.util.ArrayList;
import java.util.List;
public class ArrayListStudents {
	public static void main(String[] args) {
		Student student1 = new Student("20170001", "张三", 90);
		Student student2 = new Student("20170002", "李四", 85);
		Student student3 = new Student("20170003", "王五", 78);
		List<Student> studentList = new ArrayList<Student>(); 
		studentList.add(student1);
		studentList.add(student2);
		studentList.add(student3);
		System.out.println("集合全部记录信息：");
		for (Student student : studentList) {    //使用增强型for语句遍历集合元素
			System.out.println(student);   //自动调用toString()显示该对象的信息
		}
		System.out.println("--------------------------------");
		System.out.println("下标为1的学生信息：\n" + studentList.get(1));
		System.out.println("--------------------------------");
		studentList.remove(1);// 删除下标为1的元素
		System.out.println("删除李四记录后集合元素：");
		for (Student student : studentList) {// 使用增强型for语句遍历集合元素
			System.out.println(student);//对象自动调用toString()显示该对象的信息
		}
		System.out.println("--------------------------------");
		student3.setScore(88);// 修改王五同学的分数
		System.out.println("修改王五的分数后集合元素：");
		for (Student student : studentList) {// 使用增强型for语句遍历集合元素
			System.out.println(student);//对象自动调用toString()显示该对象的信息
		}
	}
}
