search
HomeJavajavaTutorialHow to implement a simple student performance file management system in Java?

Student performance file management system source code:

student

public class students{
    private String name;
    private String number;
    private int chinascore;
    private int mathscore;
    private int englishscore;
    private int physcore;

    public students(String name, String number, int chinascore, int mathscore, int englishscore, int physcore) {
        this.name = name;
        this.number = number;
        this.chinascore = chinascore;
        this.mathscore = mathscore;
        this.englishscore = englishscore;
        this.physcore = physcore;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public int getChinascore() {
        return chinascore;
    }

    public void setChinascore(int chinascore) {
        this.chinascore = chinascore;
    }

    public int getMathscore() {
        return mathscore;
    }

    public void setMathscore(int mathscore) {
        this.mathscore = mathscore;
    }

    public int getEnglishscore() {
        return englishscore;
    }

    public void setEnglishscore(int englishscore) {
        this.englishscore = englishscore;
    }

    public int getPhyscore() {
        return physcore;
    }

    public void setPhyscore(int physcore) {
        this.physcore = physcore;
    }
}

database

import java.util.ArrayList;
import java.util.List;

public class database {
    List<students> studentsList = new ArrayList<>();
    public database() {
        studentsList.add(new students("张三", "1", 1, 1, 1, 1));
        studentsList.add(new students("李四", "2", 8, 2, 2, 2));
        studentsList.add(new students("王五", "3", 1, 3, 3, 3));
        studentsList.add(new students("赵六", "4", 6, 4, 4, 4));
    }
    public List<students> getStudentsList() {
        return studentsList;
    }
    public void setStudentsList(List<students> studentsList) {
        this.studentsList = studentsList;
    }
}

studentdao

import java.util.List;
import java.util.Scanner;

public class studentdao {
    database database;

    public studentdao(database dataBase) {
        this.database = dataBase;
    }

    //对全部学生信息打印
    public void print() {
        List<students> list = database.getStudentsList();
        System.out.println("学生学号:" + "学生姓名" + "  语文:" + "数学:" + "英语:" + "物理:"+"学生总分");
        for (students students : database.getStudentsList()) {
            int x=students.getChinascore()+students.getMathscore()+students.getEnglishscore()+students.getPhyscore();
            System.out.println("" + students.getNumber() + "     " + students.getName() + "     " + students.getChinascore()
                    + "    " + students.getMathscore() + "   " + students.getEnglishscore() + "    " + students.getPhyscore()+"     "+x);
        }
        for(int i=0;i<=list.size();i++){
            int x=list.get(i).getChinascore()+list.get(i).getMathscore() +list.get(i).getEnglishscore()+list.get(i).getPhyscore();
            System.out.println((i+1)+list.get(i).getNumber()+list.get(i).getName()+list.get(i).getChinascore()+list.get(i).getMathscore() +list.get(i).getEnglishscore()+list.get(i).getPhyscore() +x);
        }
    }

    //添加新的学生
    public void add() {
        String number;
        String name;
        int grade1;
        int grade2;
        int grade3;
        int grade4;
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入学生的学号:");
        number = scanner.next();
        System.out.println("输入学生的姓名:");
        name = scanner.next();
        System.out.println("输入学生的语文成绩:");
        grade1 = scanner.nextInt();
        System.out.println("输入学生的数学成绩:");
        grade2 = scanner.nextInt();
        System.out.println("输入学生的英语成绩:");
        grade3 = scanner.nextInt();
        System.out.println("输入学生的物理成绩:");
        grade4 = scanner.nextInt();
        students students = new students(name, number, grade1, grade2, grade3, grade4);
        List<students> studentsList = database.getStudentsList();
        studentsList.add(students);
    }

    //输入姓名或者学号来查询学生信息
    public void searchstudent() {
        Scanner scanner = new Scanner(System.in);
            findbynumber();
    }
    //通过输入学号来查询信息
    public void findbynumber() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入学生的学号:");
        String number = scanner.next();
        for (students students : database.getStudentsList()) {
            if (students.getNumber().equals(number)) {
                System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName()
                        + "语文:" + students.getChinascore() + "数学:" + students.getMathscore()
                        + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore());
            }
        }
    }
    //通过学号来修改科目成绩
    public void changescore() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入学号:");
        String number = scanner.next();
        students students = null;
        for (students a : database.getStudentsList()) {
            if (a.getNumber().equals(number)) {
                students = a;
            }
        }
        if (students != null) {
            System.out.println("查找成功!");
            System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName()
                    + "语文:" + students.getChinascore() + "数学:" + students.getMathscore()
                    + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore());
            System.out.println("输入要修改的语文的成绩:");
            int grade1 = scanner.nextInt();
            System.out.println("输入要修改的数学的成绩:");
            int grade2 = scanner.nextInt();
            System.out.println("输入要修改的英语的成绩:");
            int grade3 = scanner.nextInt();
            System.out.println("输入要修改的物理的成绩:");
            int grade4 = scanner.nextInt();
            students.setChinascore(grade1);
            students.setMathscore(grade2);
            students.setEnglishscore(grade3);
            students.setPhyscore(grade4);
            System.out.println("修改完成!");
            System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName()
                    + "语文:" + students.getChinascore() + "数学:" + students.getMathscore()
                    + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore());
        } else {
            System.out.println("未找到该学生!");
        }
    }
    //双向冒泡排序
    public List<students> bub(List<students> studentList) {
        List<students> list = database.getStudentsList();
        students student = null;
        int left = 0, right = database.getStudentsList().size() - 1;
        while (left < right) {
            for (int i = left + 1; i <= right; i++) {
                if (list.get(left).getChinascore() + list.get(left).getMathscore() + list.get(left).getEnglishscore() + list.get(left).getPhyscore() < list.get(i).getChinascore() + list.get(i).getMathscore() + list.get(i).getEnglishscore() + list.get(i).getPhyscore()) {
                    student = list.get(i);
                    list.set(i, list.get(left));
                    list.set(left, student);

                }
            }
            left++;
            for (int i = right - 1; i >= left; i--) {
                if (list.get(right).getChinascore() + list.get(right).getMathscore() + list.get(right).getEnglishscore() + list.get(right).getPhyscore() > list.get(i).getChinascore() + list.get(i).getMathscore() + list.get(i).getEnglishscore() + list.get(i).getPhyscore()) {
                    {
                        student = list.get(i);
                        list.set(i, list.get(right));
                        list.set(right, student);
                    }
                }
                right--;
            }
        }


        return list;
    }
        //希尔排序
        public void shellSort () {
            List<students> list = database.getStudentsList();
            students student = null;
            students student1 = null;
            int j;
            for (int gap = list.size() / 2; gap > 0; gap /= 2) {
                for (int i = gap; i < list.size(); i++) {
                    student = list.get(i);
                    int tmp = student.getChinascore() + student.getMathscore() + student.getEnglishscore() + student.getPhyscore();
                    for (j = i; j >= gap && tmp > list.get(j - gap).getChinascore() + list.get(j - gap).getMathscore() + list.get(j - gap).getEnglishscore() + list.get(j - gap).getPhyscore(); j -= gap) {
                        list.set(j, list.get(j - gap));
                    }
                    list.set(j, student);
                }
            }

        }

        //快速排序
        public void quickSort1 ( int left, int right){
            List<students> studentsList = database.getStudentsList();
            if (left < right) {
                int i = left, j = right;
                students student = studentsList.get(left);
                int x = student.getChinascore() + student.getMathscore() + student.getEnglishscore() + student.getPhyscore();
                while (i < j) {
                    while ((i < j) && (studentsList.get(j).getChinascore() + studentsList.get(j).getMathscore() + studentsList.get(j).getEnglishscore() + studentsList.get(j).getPhyscore()) < x) {
                        j--;
                    }
                    if (i < j) {
                        studentsList.set(i, studentsList.get(j));
                        i++;
                    }
                    while ((i < j) && (studentsList.get(i).getChinascore() + studentsList.get(i).getMathscore() + studentsList.get(i).getEnglishscore() + studentsList.get(i).getPhyscore() > x)) {
                        i++;
                    }
                    if (i < j) {
                        studentsList.set(j, studentsList.get(i));
                        j--;
                    }
                }
                studentsList.set(i, student);
                quickSort1(left, i - 1);
                quickSort1(i + 1, right);
            }

        }
        //堆排序
    //移除位在第一个数据的根节点,并做最大堆调整的递归运算
public List<students> heapSort(List<students> studentList){
    List<students> list=studentList;
    int len = list.size();
    buildMaxHeap(list, len);
    for (int i = len - 1; i > 0; i--) {
        swap(list, 0, i);
        len--;
        heapify(list, 0, len);
    }
    return list;
}
//将堆中的所有数据重新排序堆排序(HeapSort)
    private void buildMaxHeap(List<students> studentList, int len) {
        for (int i = (int) Math.floor(len / 2); i >= 0; i--) {
            heapify(studentList, i, len);
        }
    }

    private void heapify(List<students> studentList, int i, int len) {
        int left = 2 * i + 1;
        int right = 2 * i + 2;
        int largest = i;

        if (left < len && studentList.get(left).getChinascore() + studentList.get(left).getMathscore() + studentList.get(left).getEnglishscore() + studentList.get(left).getPhyscore()< studentList.get(largest).getChinascore() + studentList.get(largest).getMathscore() + studentList.get(largest).getEnglishscore() + studentList.get(largest).getPhyscore()) {
            largest = left;
        }

        if (right < len && studentList.get(right).getChinascore() + studentList.get(right).getMathscore() + studentList.get(right).getEnglishscore() + studentList.get(right).getPhyscore()< studentList.get(largest).getChinascore() + studentList.get(largest).getMathscore() + studentList.get(largest).getEnglishscore() + studentList.get(largest).getPhyscore()) {
            largest = right;
        }

        if (largest != i) {
            swap(studentList, i, largest);
            heapify(studentList, largest, len);
        }
    }
    private void swap(List<students> studentList, int i, int j) {
        students student=studentList.get(i);
        studentList.set(i,studentList.get(j));
        studentList.set(j,student);
    }
    }

service

import java.util.Scanner;

public class service {
    private studentdao studentdao;
    ;
    private database database;

    public service(database dataBase) {
        studentdao = new studentdao(dataBase);

        this.database = dataBase;
    }
    public void start() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("1.增加学生信息");
        System.out.println("2.浏览学生信息");
        System.out.println("3.修改学生成绩");
        System.out.println("4.排序学生成绩");
        System.out.println("5.学生信息查询");

        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                add();
                break;
            case 2:
                studentdao.print();
                System.out.println("是否回到主界面0.回到1.不会");
                int k=scanner.nextInt();
                if(k==0) {
                    start();
                }
                break;
            case 3:
                changeit();break;
            case 4:
                rank();
                break;
            case 5:
                search();break;
        }
    }
    //选择排序方式
    public void rank(){
        System.out.println("1.希尔排序");
        System.out.println("2.冒泡排序");
        System.out.println("3.快速排序");
        System.out.println("4.堆排序");
        System.out.println("输入0返回菜单");
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        switch (a){
            case 1:
                studentdao.shellSort();
                studentdao.print();
                System.out.println("是否回到主界面0.回到1.不会");
                int p=scanner.nextInt();
                if(p==0) {
                    start();
                }
                break;
            case 2:
                studentdao.bub(database.getStudentsList());
                studentdao.print();

                System.out.println("是否回到主界面0.回到1.不会");
                int k=scanner.nextInt();
                if(k==0) {
                    start();
                }
                break;
            case 3:
                studentdao.quickSort1(0,database.getStudentsList().size()-1);
                studentdao.print();
                System.out.println("是否回到主界面0.回到1.不会");
                int o=scanner.nextInt();
                if(o==0) {
                    start();
                }
                break;
            case 4:
                studentdao.heapSort(database.getStudentsList());
                studentdao.print();
                System.out.println("是否回到主界面0.回到1.不会");
                int k1=scanner.nextInt();
                if(k1==0) {
                    start();
                }
                break;
            case 0:start();
                break;
        }
    }
    //查找学生信息
    public void search(){
        studentdao.searchstudent();
        Scanner scanner=new Scanner(System.in);
        System.out.println("是否回到主界面0.回到1.不会");
        int k=scanner.nextInt();
        if(k==0) {
            start();
        }
    }
    //更改学生信息

    public void changeit(){
            studentdao.changescore();
        System.out.println("是否回到主界面0.回到1.不会");
        Scanner scanner=new Scanner(System.in);
        int k=scanner.nextInt();
        if(k==0) {
            start();
        }
    }
    //增加学生
    public void add(){
        studentdao.add();
        System.out.println("是否回到主界面0.回到1.不会");
        Scanner scanner=new Scanner(System.in);
        int k=scanner.nextInt();
        if(k==0) {
            start();
        }
    }

}

text

public class text {
    public static void main(String[]args){
        database database = new database();
        service studentsSer=new service(database);
       studentsSer.start();
    }
}

The above is the detailed content of How to implement a simple student performance file management system in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list?How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to safely convert Java objects to arrays?How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How do I convert names to numbers to implement sorting and maintain consistency in groups?How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the default run configuration list of SpringBoot projects in Idea for team members to share?How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.