7.27作业
public class Xueyuan { private String name; private String sex ; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Xueyuan(String name,String sex) { super(); this.name = name; this.sex = sex; } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class XueyuanTest { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { Xueyuan stu = new Xueyuan("李明","男"); Xueyuan stu2 = new Xueyuan("张三","男"); Xueyuan stu3 = new Xueyuan("李娜","女"); Map map = new HashMap(); map.put("JACK",stu); map.put("ZED",stu2); map.put("ROSE",stu3); System.out.println("请输入学员英文名:"); String eName = sc.next(); if(map.containsKey(eName)) { Xueyuan xue = (Xueyuan)map.get(eName); System.out.println("英文名为"+eName+"的学员名字:"+xue.getName()+",性别是:"+xue.getSex()); }else { System.out.println("没有找到该学员信息"); } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步