学生管理系统项目演示

package com.gds.demospring.test;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Author 龚道松
 * @Date 2019/3/5 0005 17:27
 * @Wersion 1.0
 **/
public class StudentMannger {

    public static void main(String[] args) {
        // 创建集合对象,用于存储学生数据
        ArrayList arrayList = new ArrayList();
        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 退出");
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入你的选择(1-5): ");
            String s = sc.nextLine();

            switch (s) {
                case "1":
                    // 查询所有学生
                    findAllStudent(arrayList);
                    break;
                case "2":
                    //添加学生
                    addStudent(arrayList);
                    break;
                case "3":
                    //删除学生
                    deleteStudent(arrayList);
                    break;
                case "4":
                    //修改学生
                    modifyStudent(arrayList);

                    break;
                case "5":
                    // 退出
                default:
                    System.out.println("谢谢你的使用!");
                    System.exit(0);
                    break;
            }
        }
    }

    // 修改学生
    private static void modifyStudent(ArrayList arrayList) {
        // 键盘录入学号
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要修改的学生学号: ");
        String id = sc.nextLine();
        int index = -1;
        for (int x=0; x arrayList) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生学号: ");
        String id = sc.nextLine();
        int index = -1;
        for (int x=0; x arrayList) {
        // 键盘录入学生信息
        Scanner sc = new Scanner(System.in);

        String id;
        while (true) {
            System.out.println("请输入学生学号: ");
            id = sc.nextLine();
            boolean flag = false;
            for (int i = 0; i < arrayList.size(); i++) {
                Student s = arrayList.get(i);
                if (s.getId().equals(id)) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                System.out.println("此id被占用,请重新输入!");
            } else {
                break;
            }
        }

        System.out.println("请输入学生姓名: ");
        String name = sc.nextLine();
        System.out.println("请输入学生年龄: ");
        String age = sc.nextLine();
        System.out.println("请输入学生地址: ");
        String address = sc.nextLine();

        // 创建学生对象
        Student s = new Student();
        s.setId(id);
        s.setName(name);
        s.setAge(age);
        s.setAddress(address);

        // 添加到集合
        arrayList.add(s);
        System.out.println("添加成功");
    }

    // 查询所有学生信息
    private static void findAllStudent(ArrayList arrayList) {
        //判断有没有数据
        if (arrayList.size() == 0){
            System.out.println("不好意思,目前没有你要查询的学生信息,请回去重新选择你的操作!");
            return;
        }
        System.out.println("学号\t\t姓名\t年龄\t地址");
        for (int i = 0; i < arrayList.size(); i++) {
            Student s = arrayList.get(i);
            System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getAge()+"\t"+s.getAddress());
        }
    }
}

 

package com.gds.demospring.test;

/**
 * @Author 龚道松
 * @Date 2019/3/5 0005 17:26
 * @Wersion 1.0
 **/
public class Student {

    String id;
    String name;
    String age;
    String address;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public Student() {
    }

    public Student(String id, String name, String age, String address) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.address = address;
    }
}

 

你可能感兴趣的:(JavaSE)