import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
//建立一个链表,每个结点包括:学号、姓名、性别、年龄。输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则将此结点删去
public class list_delete {
public static void main(String[] args){
LinkedList<Student> stu=new LinkedList<Student>();
stu.add(new Student("1001","zhangsan","男",20));
stu.add(new Student("1002","lisi","男",23));
stu.add(new Student("1003","wangwu","女",22));
stu.add(new Student("1004","liuliu","女",21));
Iterator<Student> iter=stu.iterator();
while(iter.hasNext()){
iter.next().showInfo();
}
int age=new Scanner(System.in).nextInt();
iter=stu.iterator();
while(iter.hasNext()){
Student s=iter.next();
if(s.getSage()==age){
stu.remove(s);
break;
}
}
iter=stu.iterator();
while(iter.hasNext()){
iter.next().showInfo();
}
}
}
class Student{
private String sno;
private String sname;
private String sex;
private int sage;
public Student(String sno, String sname, String sex, int sage) {
this.sno = sno;
this.sname = sname;
this.sex = sex;
this.sage = sage;
}
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public void showInfo() {
System.out.println("Student [sno=" + sno + ", sname=" + sname + ", sex=" + sex
+ ", sage=" + sage + "]");
}
}