学生管理系统编程题

编写代码完成如下要求:
完成学生类 Student 的编写
属性:姓名、年龄、学科、成绩等
完成文件操作类 FileOperate 的编写
功能:void write(List list) 将集合数据写入文件
List read(File file) 读取文件中存储的集合数据
完成学生管理类 StudentManage 的编写
功能:

  1. 控制台录入学生考试成绩(学号、姓名、学科、成绩),退出当前菜单时将学生信息保存至文件中
  2. 控制台修改学生考试成绩(学号、学科),退出当前菜单时将学生信息保存至文件中
  3. 控制台查看指定学科的全部学生成绩(从高到低逆序排序)
  4. 控制台查看指定学生的全部成绩信息(从高到低逆序排序)
import java.io.Serializable;

public class Student implements Serializable, Comparable<Student>{
	private String code;//学号
    private String name;//名字
    private String subject;//学科
    private int score;//成绩
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	//无参构造
	public Student() {
		super();
	}
	//四参构造
	public Student(String code, String name, String subject, int score) {
		super();
		this.code = code;
		this.name = name;
		this.subject = subject;
		this.score = score;
	}
	//两参构造
	public Student(String code, String subject) {
		super();
		this.code = code;
		this.subject = subject;
	}
	@Override
	public int compareTo(Student o) {
		if (this.getSubject().equals(o.getSubject())) {
            return o.getScore() - this.getScore();
        } else {
            return o.getSubject().compareTo(this.getSubject());
        }
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + score;
		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Student)) {
			return false;
		}
		Student other = (Student) obj;
		if (code == null) {
			if (other.code != null) {
				return false;
			}
		} else if (!code.equals(other.code)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		if (score != other.score) {
			return false;
		}
		if (subject == null) {
			if (other.subject != null) {
				return false;
			}
		} else if (!subject.equals(other.subject)) {
			return false;
		}
		return true;
	}
	
	
    
}

public class FileOperate {
    public static <T> void write(List<T> list, File file) {
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
        }

        FileOutputStream fos = null;
        ObjectOutputStream oos = null;

        try {
            fos = new FileOutputStream(file);
            oos = new ObjectOutputStream(fos);

            oos.writeObject(list);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static <T> List<T> read(File file) {
        List<T> list = new ArrayList<>();

        if (!file.exists()) {
            return list;
        }
        
        FileInputStream fis = null;
        ObjectInputStream ois = null;

        try {
            fis = new FileInputStream(file);
            ois = new ObjectInputStream(fis);

            list = (List<T>) ois.readObject();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return list;
    }
}
学生管理设计型题目) (1)创建C# 控制台应用程序L4_3。 (2)在程序中创建一个学生类Student,包含以下成员:  定义私有字段:学号s_no,姓名s_name, 班级s_class,成绩s_score。  定义Student的构造函数,初始化4个私有字段。  定义四个公有属性S_no,S_name,S_class以及S_score,分别用于封装对各字段读写访问。 (3)再定义一个StudentInfo,用于对学生信息进行管理:该包括下列成员:  存放学生信息的Student[]型的私有字段成员m_list ;  存储学生最大数量的私有字段m_maxcapacity;  存储当前学生数量的私有字段m_length;  带参数的构造函数,根据指定长度对各私有字段进行初始化。  定义的只读公有属性:Maxcapcity属性、Currentlength属性、 Restlength属性,分别用于返回列表的最大容量、已存信息的容量、剩余的最大容量。  定义一个索引函数,用于实现根据学生的学号对信息进行读、写访问。(无论读或写操作都要求先判断学生是否存在)。  定义公有方法AddInfo(返回型为bool),用于向学生信息列表中添加学生信息(需要判断添加操作能否进行,即列表是否已满)。  定义一个公有方法DeleteInfo返回型为bool),用于根据学生学号删除信息。(需要判断学生是否存在) (4)在外部中进行StudentInfo的各种功能进行测试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值