栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java学生成绩管理系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java学生成绩管理系统

目录

1学生成绩管理系统部分

2student类

3课程类:存储学生的课程名和成绩

4StudentAvgComparator尺子:实现以学生的平均成绩进行排序 


1学生成绩管理系统部分

将学生成绩管理系统定义为一个static变量,实现持久化

使用了ObjectInputStream(.writeObject将对象写入文件)和ObjectOutput(.readObject将文件中的对象读入流),这就要求流中的对象必须是可序列化的,即实现了Serializable接口

package StudentManagerSystem;

import java.io.*;
import java.util.*;

public class Ex8 {
    private static ArrayList studentList = new ArrayList();//静态studentList集合存储学生信息

    public static void main(String[] args) throws IOException {

        readStudentFromFile();//先从文件中读入原来保存过的学生数据
        Scanner temp = new Scanner(System.in);

        while (true) {
            System.out.println("请选择操作");
            System.out.println("1 查看所有学生");
            System.out.println("2 添加学生信息");
            System.out.println("3 修改学生信息");
            System.out.println("4 删除学生信息");
            System.out.println("5 退出系统");
            System.out.println("6 根据学生的学号查找学生信息");
            System.out.println("7 根据学生的平均分降序排序");
            System.out.println("8 按照学生的学号升序");
            System.out.println("9 根据学生的姓名查找学生信息");
            System.out.println("10 查看所有学生的总分和平均分");
            //输入选项
            String choice = temp.nextLine();
            //判断
            switch (choice) {
                case "1":
                    show(studentList);
                    System.out.println("系统中共存有"+ studentList.size()+"个学生");
                    break;
                case "2":
                    add(studentList);
                    break;
                case "3":
//                    modify(array);
                    break;
                case "4":
                    delete(studentList);
                    writeStudentToFile(studentList);//修改数据之后立即更新硬盘文件
                    break;
                case "6":
                    findStudentBystudentID();
                    break;
                case "7":
                    orderByAvgScore();
                    break;
                case "8":
                    orderByNum();
                    break;
                case "9":
                    findStudentBystudentName();
                    break;
                case "10":
                    showStudentAvgAndTotalScore();
                    break;
                case "5":
                    System.out.println("系统已成功退出");
                    System.exit(0);
                default:
                    System.out.println("您的输入有误,请重新选择!");
            }
        }
    }

    //查询学生信息方法
    private static void show(ArrayList array){
        System.out.println("共储存了"+array.size()+"名学生信息");
        if(array.size() == 0){
            System.out.println("暂时未存储任何学生信息,请重新选择。");
            return;
        }
        for(int i=0;i array){
        Scanner temp = new Scanner(System.in);
        String num;
        while(true){
            System.out.println("请输入新同学学号:");
            num = temp.nextLine();
            //判断是否重复学号
            boolean flag = false;//默认未重复
            for(int i=0;i array){
        Scanner temp = new Scanner(System.in);
        System.out.println("请输入需要删除的学生学号:");
        String num = temp.nextLine();
        for(int i=0;i)in.readObject();//读入的是Object类型,需要强制类型转换
//            Object object=in.readObject();
            if (studentList.size()==0) {
                System.out.println("未读取到数据");
            }
            else {
                studentList =(ArrayList)studentList;
            }
            System.out.println("从指定文件读取学生数据完毕");
        } catch (EOFException e){
            System.out.println("读入完毕,没有数据可读了");;
        } catch (FileNotFoundException e){
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void findStudentBystudentID() {
        Scanner temp = new Scanner(System.in);
        System.out.println("请输入需要查找的学生学号:");
        String num = temp.nextLine();
        for (int i = 0; i < studentList.size(); i++) {
            Student s = studentList.get(i);
            if (s.getNum().equals(num)) {
                System.out.println("第"+i+"同学的学号为"+s.getNum()+"第"+i+"同学的姓名为"+s.getName()+"第"+i+"同学的性别为"+s.getSex()+"第"+i+"同学的班级为"+s.getsClass());
                s.getCourses();
            }
        }
    }

    public static void findStudentBystudentName() {
        Scanner temp = new Scanner(System.in);
        System.out.println("请输入需要查找的学生学号:");
        String name = temp.nextLine();
        for (int i = 0; i < studentList.size(); i++) {
            Student s = studentList.get(i);
            if (s.getName().equals(name)) {
                System.out.println("第"+i+"同学的学号为"+s.getNum()+"第"+i+"同学的姓名为"+s.getName()+"第"+i+"同学的性别为"+s.getSex()+"第"+i+"同学的班级为"+s.getsClass());
                s.getCourses();
            }
        }
    }


    public static void orderByAvgScore () {
        Comparator avgComparator = new StudentAvgComparator();
        Collections.sort(studentList,avgComparator);
        System.out.println(studentList.toString());
    }
    public static void orderByNum(){
        Collections.sort(studentList);//按照学号升序排序
        System.out.println(studentList.toString());
    }

    public static void showStudentAvgAndTotalScore(){
        for (int i=0;i 

2student类
package StudentManagerSystem;

import java.io.Serializable;
import java.util.*;

public class Student implements Comparable,Serializable {
    private String num;//学号
    private String name;//姓名
    private String sex;//性别
    private String sClass;//班级
    private double Avg;//平均分
    private List course =new ArrayList();//成绩
//    private List listCourse=new ArrayList();

    public Student() {
    }

    public void setCourses() {
        ArrayList c1=new ArrayList();
        Scanner sc = new Scanner(System.in);
        Scanner sc1 =new Scanner(System.in);
        System.out.println("请输入课程的数量:");
        int num = sc.nextInt();
        for (int i = 0;i list=new ArrayList();
        list=this.course;
//        for (Object num:list){
//            System.out.println(num);
//        }
        for (int i=0;i 

3课程类:存储学生的课程名和成绩
package StudentManagerSystem;

import java.io.Serializable;

public class Course implements Serializable {
    public String courseName;//课程姓名
    public double courseSorce;//课程成绩

    public Course(String courseName, double courseSorce) {
        this.courseName = courseName;
        this.courseSorce = courseSorce;
    }

    public Course() {
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public double getCourseSorce() {
        return courseSorce;
    }

    public void setCourseSorce(double courseSorce) {
        this.courseSorce = courseSorce;
    }

    @Override
    public String toString() {
        return "Course{" +
                "courseName='" + courseName + ''' +
                ", courseSorce=" + courseSorce +
                '}';
    }
}

4StudentAvgComparator尺子:实现以学生的平均成绩进行排序 
package StudentManagerSystem;


import java.util.Comparator;

public class StudentAvgComparator implements Comparator {
    public int compare(Student o1,Student o2){
        return (int) (o2.getAvg()-o1.getAvg());
    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/978023.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号