码迷,mamicode.com
首页 > 其他好文 > 详细

新手小白简单的学生管理系统

时间:2021-01-14 10:42:47      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:email   dex   简单   public   creat   system   scanner   ack   选择   

package com.ustb.ly;

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

/**
 * @author LinYue
 * @email ustb2021@126.com
 * @create 2021-01-12 21:07
 */
public class StudentManger {
    static ArrayList<Student> students = new ArrayList<>();
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        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("请输入你的选择:");

            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    add();
                    break;

                case 2:
                    delete();
                    break;

                case 3:
                    update();
                    break;
                case 4:
                    query();
                    break;

                case 5:
                    quit();
            }
        }
    }

    private static void update() {
        System.out.println("输入您想修改学生的序号:");
        int index = scanner.nextInt();
        if (index <= 0 || index > students.size()) {    //修改学生学号不存在
            System.out.println("序号有误!请重新输入");
            update();
        }else {
            System.out.println("输入您修改后的学生:");
            Student student1 = new Student(scanner.next(), scanner.nextInt());

            students.set(index - 1, student1);
        }
    }

    private static void delete() {

        System.out.println("输入您想删除学生的序号:");
        int index = scanner.nextInt();
        if (index <= 0 || index > students.size()) {    //删除学生学号不存在
            System.out.println("序号有误!请重新输入");
            delete();
        }else {
            students.remove(index - 1);
        }
    }

    private static void quit() {
        System.exit(0);
    }

    public static void add() {
        System.out.println("请依次输入学生姓名和年龄:");
        Student student = new Student();
        student.setName(scanner.next());
        student.setAge(scanner.nextInt());
        students.add(student);
    }

    public static void query() {
        for (Student student : students) {
            System.out.println(student);
        }
    }
}

  

新手小白简单的学生管理系统

标签:email   dex   简单   public   creat   system   scanner   ack   选择   

原文地址:https://www.cnblogs.com/HuziLin/p/14269466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!