你好,你要的学生信息管理系统。
(1) Student类
import java.io.Serializable;
/**
* @author liuxe
* @since JDK 1.7.0_79
*/
public class Student implements Serializable {
private int stuId;
private String name;
private String major;
private String sex;
private String contactWay;
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getContactWay() {
return contactWay;
}
public void setContactWay(String contactWay) {
this.contactWay = contactWay;
}
}
(2) StuMis类
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author liuxe
* @since JDK 1.7.0_79
*/
public class StuMis {
public static ListstudentList = new ArrayList ();
public static boolean add(Student student) {
return studentList.add(student);
}
public static boolean remove(Student student) {
return studentList.remove(student);
}
public static boolean update(Student student) {
for (Student dto : studentList) {
if (student.getStuId() == dto.getStuId()) {
studentList.remove(dto);
}
}
return studentList.add(student);
}
public static Student queryByStuId(int id) {
for (Student dto : studentList) {
if (id == dto.getStuId()) {
return dto;
}
}
return null;
}
public static ListqueryByName(String name) {
ListreturnList = new ArrayList ();
for (Student dto : studentList) {
if (name.equals(dto.getName())) {
returnList.add(dto);
}
}
return returnList;
}
public static void saveToFile() {
try {
ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(
new File("." + File.separator + "student.dat")));
oo.writeObject(studentList);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void readFromFile() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
new File("." + File.separator + "student.dat")));
studentList = (List) ois.readObject();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
(3)、StuMisTest类:主函数测试学生信息管理系统
import java.util.List;
/**
* @author liuxe
* @since JDK 1.7.0_79
*/
public class StuMisTest {
public static void main(String[] args) {
Student student = new Student();
student.setStuId(1);
student.setName("AAA");
student.setMajor("AAAA");
student.setSex("A");
student.setContactWay("AA");
Student student2 = new Student();
student2.setStuId(2);
student2.setName("BBB");
student2.setMajor("BBBB");
student2.setSex("B");
student2.setContactWay("BB");
Student student3 = new Student();
student3.setStuId(3);
student3.setName("CCC");
student3.setMajor("CCCC");
student3.setSex("C");
student3.setContactWay("CC");
//A、 增加一个学生记录
StuMis.add(student);
StuMis.add(student2);
StuMis.add(student3);
//B、 删除一个学生记录
StuMis.remove(student2);
//C、 修改学生信息
student.setMajor("DDDD");
StuMis.update(student);
//D、 根据学号查找学生
Student studentXX = StuMis.queryByStuId(3);
//E、 根据姓名查找学生。。。
ListstudentOO = StuMis.queryByName("AAA");
//F、 将集合中所有学生信息存储到student.dat中。
StuMis.saveToFile();
//G、 再次运行系统时加载student.dat中的学生信息,后支持A~E基本操作。
StuMis.readFromFile();
}
}