JAVA——简单的信息录入系统

类:Student

public class Student {

    String name;
    int age;
    long id;

    public Student(){

    }
//    public Student(String name, int age, long id) {
//        this.name = name;
//        this.age = age;
//        this.id = id;
//    }

    public long getId() {
        return id;
    }

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

//    public String getName() {
//        return name;
//    }
    public void setName(String name) {
        this.name = name;
    }
//    public int getAge() {
//        return age;
//    }
    public void setAge(int age) {
        this.age = age;
    }

    public void show(){
        System.out.println("姓名:"+name + "\t年龄:"+age);
    }
}

类:Manger

import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Manger {
    public static void main(String[] args) {

        System.out.println("学生信息管理系统");
        System.out.println("请输入选择序号!");

        Scanner sc = new Scanner(System.in);

        HashMap<Long, Student> map = new HashMap<>();

        boolean input = true;
        while (input){

            System.out.println("1.录入学生信息");
            System.out.println("2.查看学生信息");
            System.out.println("3.删除学生信息");
            System.out.println("4.查看所以学生信息");
            System.out.println("5.退出系统");

            int num = sc.nextInt();
            switch (num) {
                case 1: {
                    Student shu1 = new Student();

                    System.out.println("请输入学号!");
                    shu1.setId(sc.nextInt());

                    System.out.println("请输入姓名!");
                    shu1.setName(sc.next());

                    System.out.println("请输入年龄!");
                    shu1.setAge(sc.nextInt());

                    map.put( shu1.getId(), shu1);

                    System.out.println("学生信息录入完毕,请重新选择序号!");
                    continue;
                }

                case 2: {
                    System.out.println("已经录入系统的学生:");
                    for (Long input_id : map.keySet())
                        System.out.println("学号:"+input_id+"\t");

                    System.out.println("请输入学号!");
                    map.get( (long)sc.nextInt() ).show();

                    System.out.println("学生信息显示完毕,请重新选择序号!");
                    continue;
                }

                case 3: {
                    System.out.println("请输入学号!");
                    map.remove( (long)sc.nextInt() );

                    System.out.println("学生信息删除完毕,请重新选择序号!");
                    continue;
                }

                case 4 : {
                    Iterator<Student> it = map.values().iterator();
                    System.out.println("请输入学号!");
                    while (it.hasNext()) {
                        it.next().show();
                    }
                    System.out.println("学生信息显示完毕,请重新选择序号!");
                    continue;
                }

                case 5 : {
                    System.out.println("系统成功退出!");
                    input = false;
                    break;
                }
                default :
                    System.out.println("错误输入,请重新选择序号!!!!");
            }
        }

    }
}




版权声明:本文为qq_62819483原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。