zoukankan      html  css  js  c++  java
  • 学生管理类 容器

    package student;

    public class student {

    private String num;
    private String name;
    public student(String num,String name){
    this.num = num;
    this.name = name;
    }

    @Override
    public String toString() {
    return "student [num=" + num + ", name=" + name + "]";
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

    }

    package student;

    import java.util.Map;
    import java.util.Scanner;
    import java.util.HashMap;

    public class test {
    private student S1 = new student("1","zhang");
    private student S2 = new student("2","li");
    private student S3 = new student("3","wang");
    Map<String,student> map =
    new HashMap<String, student>();
    public test(){
    map.put("1",S1);
    map.put("2",S2);
    map.put("3",S3);
    }
    public String getStr(){
    //System.out.print("请输入:");
    Scanner in = new Scanner(System.in);
    String Str = in.next();
    return Str;
    }
    public void keyFind(){
    System.out.println("请输入键值查询:");
    String key = getStr();
    boolean contains = map.containsKey(key);

    if(contains){
    System.out.println("存在该学生 "+key+map.get(key).toString());
    }
    else{
    System.out.println("不存在该学生 "+key);
    }

    }

    public void Add(){
    System.out.print("请输入键值进行添加:");
    String key = getStr();
    System.out.print("请输入学号:");
    String num = getStr();
    System.out.print("请输入姓名:");
    String name = getStr();
    student S = new student(num,name);
    map.put(key, S);
    }
    public void getSize(){
    System.out.println("学生个数:"+map.size());

    }
    public void remove(){
    System.out.println("输入键值进行删除");
    String key = getStr();
    map.remove(key);
    }
    public static void main(String[] args) {
    test t = new test();

    t.keyFind();
    t.Add();
    t.getSize();
    t.remove();
    t.getSize();

    }

    }

  • 相关阅读:
    centos7安装mysql8 ERROR! The server quit without updating PID file
    linux桌面系统开启windows远程访问
    intellij ide 激活(转发)
    intellij ide调用一个对象所有的set方法
    linux服务器磁盘挂载
    互联网公司研发团队服务器开发工具清单
    intellij ide 集成cmder
    maven 私服上有jar包但是却下载不下来
    java开发人员win10配置
    996 icu我能为你做什么?
  • 原文地址:https://www.cnblogs.com/the-wang/p/6628797.html
Copyright © 2011-2022 走看看