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

    }

    }

  • 相关阅读:
    PowerDesigner反向生成物理数据模型
    10个JavaScript的难点
    Golang数组拼接为字符串
    Golang对元素slice并去重
    golang获取开始日期和结束日期的所有日期列表
    go数组取交集截取
    golang学习笔记
    go语言time包简单使用
    windows为GO设置代理解决go get缓慢
    sublime使用笔记
  • 原文地址:https://www.cnblogs.com/the-wang/p/6628797.html
Copyright © 2011-2022 走看看