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();

    }

    }

  • 相关阅读:
    定位IO瓶颈的方法,iowait低,IO就没有到瓶颈?
    10分钟检查自己的系统性能数据
    netperf使用指南
    如何看内核源码
    xxx
    os.path 模块
    目前中国智能语音产业的格局、现状
    NLP-python 自然语言处理01
    15本经典金融投资著作
    写给步入工作的自己
  • 原文地址:https://www.cnblogs.com/the-wang/p/6628797.html
Copyright © 2011-2022 走看看