java实现学生成绩档案管理系统

时间:2022-10-08 10:28:46

本文实例为大家分享了java实现学生成绩档案管理系统的具体代码,供大家参考,具体内容如下

实验要求

• 学生信息录入,信息包括学号、姓名、专业、四门课成绩、总分、名次;
• 系统可对学生信息浏览、增加、删除和修改;
• 按学生成绩确定名次及信息输出,双向冒泡排序、希尔排序、快速排序、堆 排序。
• 要求可对学生信息查询,根据学号或姓名进行查找;
• 信息修改仅可修改四门课成绩;
• 文件存取学生信息

实验设计

• 新增学生信息(包括学号、姓名、专业、4门课成绩……)
• 浏览学生信息(对学生排序后信息进行浏览)
• 删除学生信息(删除指定学生的信息,可给用户选择检索指定项)
• 查找学生信息(查找符合条件的某条记录)
• 保存学生信息(保存学生成绩档案信息到文本文件)
• 加载学生信息(登录系统后将磁盘文件中保存的学生成绩信息读取到内存中)

实验分析

初步分析

本实验采用dao模式进行编写,由于暂时没有学习数据库,故新建一个类来模拟保存数据库,此外,本人想法是将数据保存于excel文件中,并从excel文件中读取数据。

算法设计

快速排序

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
     * 快速排序
     * 递归
     */
    private void quickSort(List<StuInfo> stuInfosList, int left, int right) {
        if (left >= right) {
            return ;
        }
        int l = left;
        int r = right;
        //基准值,取中间
        int key = stuInfosList.get(left).getSum();
 
        boolean flag=true;
        //交换容器
        StuInfo student;
        while (l != r) {
 
            if(flag){
                if(key<stuInfosList.get(r).getSum()){
                    student = stuInfosList.get(r);
                    stuInfosList.set(r, stuInfosList.get(l));
                    stuInfosList.set(l, student);
                    flag=false;
                }else{
                    r--;
                }
            }else {
                if (key>stuInfosList.get(l).getSum()){
                    student = stuInfosList.get(r);
                    stuInfosList.set(r, stuInfosList.get(l));
                    stuInfosList.set(l, student);
                    flag=true;
                }else {
                    l++;
                }
            }
        }
        quickSort(stuInfosList,left, r - 1);
        quickSort(stuInfosList, l + 1, right);
}

双向冒泡排序

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
     * 双向冒泡排序
     */
    private void doubleBubbleSort(List<StuInfo> stuInfosList) {
        //设置一个交换容器
        StuInfo student;
        //左右指针
        int left = 0, right = stuInfosList.size() - 1;
        while (left < right) {
            for (int i = left + 1; i <= right; i++) {
                if (stuInfosList.get(left).getSum() < stuInfosList.get(i).getSum()) {
                    student = stuInfosList.get(i);
                    stuInfosList.set(i, stuInfosList.get(left));
                    stuInfosList.set(left, student);
                }
            }
            left++;
            for (int i = right; i >= left; i--) {
                if (stuInfosList.get(right).getSum() > stuInfosList.get(i).getSum()) {
                    student = stuInfosList.get(i);
                    stuInfosList.set(i, stuInfosList.get(right));
                    stuInfosList.set(right, student);
                }
            }
            right--;
        }
    }

堆排序

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
     * 堆排序
     */
    private void heapSort(List<StuInfo> stuInfosList) {
        //建堆
        buildHeap(stuInfosList);
        StuInfo student;
        for (int i = stuInfosList.size() - 1; i >= 1; i--) {
            //交换
            student = stuInfosList.get(i);
            stuInfosList.set(i, stuInfosList.get(0));
            stuInfosList.set(0, student);
            //堆调整
            heapfity(stuInfosList, 0, i - 1);
        }
    }
 
    /**
     * 堆调整
     */
    private void heapfity(List<StuInfo> stuInfosList, int index, int len) {
        int lchild = index * 2 + 1;
        int rchild = index * 2 + 2;
 
        StuInfo student;
        int temp = 0;
 
        if (lchild <= len && rchild <= len) {
            temp = stuInfosList.get(lchild).getSum() < stuInfosList.get(rchild).getSum() ? lchild : rchild;
        } else if (lchild <= len) {
            temp = lchild;
        } else if (rchild <= len) {
            temp = rchild;
        }
        //
        if (stuInfosList.get(temp).getSum() < stuInfosList.get(index).getSum()) {
            student = stuInfosList.get(temp);
            stuInfosList.set(temp, stuInfosList.get(index));
            stuInfosList.set(index, student);
        }
    }
 
    /**
     * 建立小根堆
     */
    private void buildHeap(List<StuInfo> stuInfosList) {
        for (int i = stuInfosList.size() / 2 - 1; i >= 0; i--) {
            heapfity(stuInfosList, i, stuInfosList.size() - 1);
        }
    }

希尔排序

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
     * 希尔排序
     */
    private void shellSort(List<StuInfo> stuInfosList) {
 
        int step = stuInfosList.size() / 2;
        while (step >= 1) {
 
            for (int start = 0; start < step; start++) {
                insertSort(stuInfosList, step, start);
            }
            step /= 2;
        }
    }
 
    /**
     * 希尔排序循环内使用的插入排序
     */
    private void insertSort(List<StuInfo> stuInfosList, int step, int start) {
        //交换容器
        StuInfo student;
        for (int i = start + step; i < stuInfosList.size(); i += step) {
            for (int j = i; j - step >= 0 && stuInfosList.get(j).getSum() > stuInfosList.get(j - step).getSum(); j -= step) {
                student = stuInfosList.get(j);
                stuInfosList.set(j, stuInfosList.get(j - step));
                stuInfosList.set(j - step, student);
            }
        }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_45436831/article/details/114602373