Home  >  Article  >  Java  >  Implementing a simple student management system using List in Java

Implementing a simple student management system using List in Java

php是最好的语言
php是最好的语言Original
2018-08-06 14:19:012105browse

As a JAVA programmer, whether a beginner or an expert, the student management system is a good example. Beginners use arrays, lists, etc. to write simple student management systems, while experts use swing databases. A student management system with an interface. Without further ado, today I will use List to implement the student management system.

The student management system is mainly aimed at students. We first write out the student objects.

package TestProject;public class student {
    String name;
    String age;    public String getName() {        return name;
    }    public void setName(String name) {        this.name = name;
    }    public String getAge() {        return age;
    }    public void setAge(String age) {        this.age = age;
    }
}

Here are some * get and set methods (I just wrote two of them because I was lazy)

    System.out.println("欢迎来到学生管理系统");
    System.out.println("【1】注册");
    System.out.println("【2】查看");
    System.out.println("【3】修改");
    System.out.println("【4】删除");
    System.out.print("请选择您的操作:");

The following is the implementation of each function on the main page. Not much nonsense. Code

package TestProject;import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class Testdemo02 {
    /**
     * 操作界面
     */
    static Scanner sca = new Scanner(System.in);    static List<student> l = new ArrayList<student>();    static student c = new student();    static boolean stu = true;    public static void main(String[] args) {
        System.out.println("欢迎来到学生管理系统");
        System.out.println("【1】注册");
        System.out.println("【2】查看");
        System.out.println("【3】修改");
        System.out.println("【4】删除");
        System.out.print("请选择您的操作:");        while(stu) {
            String stus = sca.nextLine();            switch(stus) {            case "1":
                add();                break;            case "2":
                sel();                break;            case "3":
                set();                break;            case "4":
                del();                break;
            }
        }
    }    /***
     * 添加功能
     */
    static void add() {        while(stu) {
            System.out.println("请输入学生姓名");
            c.setName(sca.nextLine());
            System.out.println("请输入学生年龄");
            c.setAge(sca.nextLine());
            System.out.println("添加成功");
            l.add(c);            break;
        }
    }    /**
     * 查询功能
     */
    static void sel() {        for (student c : l) {
            System.out.println("姓名:"+c.getName()+" "+"年龄:"+c.getAge());
        }
    }    /**
     * 删除功能
     */
    static void del() {
        System.out.println("请输入要删除的姓名");
        String names = sca.nextLine();        for(int i=0;i<l.size();i++) {            if(names.equals(l.get(i).getName())) {
                System.out.println("找到学生正在删除");
                l.remove(i);
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败未找到学生");
            }
        }
    }    /**
     * 修改功能
     */
    static void set() {
        System.out.println("请输入要修改学生的姓名");
        String names = sca.nextLine();        for(int i=0;i<l.size();i++) {            if(names.equals(l.get(i).getName())) {
                System.out.println("发现学生正在修改");
                System.out.println("请输入修改后的姓名");
                String name = sca.nextLine();
                l.get(i).setName(name);
                System.out.println("请输入修改后的年龄");
                String age = sca.nextLine();
                l.get(i).setAge(age);
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败未找到学生");
            }
        }
    }
}

Do you think it’s very simple after reading these? It is very suitable for beginners to practice.
Isn’t it very simple to complete a simple student management system?

Related articles:

Student performance management system

How shell implements student performance management system

The above is the detailed content of Implementing a simple student management system using List in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn