- import java.util.List;
- public class StudentManager {
- /**
- * 显示所有学生信息的方法
- */
- public voidshowAllStudentInfo(List stus) {
- for (Student student : stus) {
- System.out.println(student);
- }
- }
- /**
- * 根据学员学号查询
- */
- public voidgetStudentById(intid, List stus) {
- intcount = 0;
- for (Student student : stus) {
- if(student.getId() == id) {
- System.out.println(student);
- } else {
- count++;
- }
- }
- if(count == stus.size()) {
- System.out.println("没有该学号的学员");
- }
- }
- /**
- * 根据学员学号删除学生信息
- */
- public voiddeleteById(intid, List stus) {
- intindex = 0;
- for(inti = 0; i < stus.size(); i++) {
- Student student = stus.get(i);
- if(student.getId() == id) {
- index = i;
- break;
- }
- }
- stus.remove(index);
- }
- /**
- * 根据学号修改学员信息
- */
- public voidupdateStudent(intuid, List stus, Student student) {
- intindex = 0;
- for(inti = 0; i < stus.size(); i++) {
- if(stus.get(i).getId() == uid) {
- index = i;
- break;
- }
- }
- stus.set(index, student);
- }
- }
来源: http://www.bubuko.com/infodetail-1985775.html