这道java编程题咋写呀?
图片太小了,学生信息我乱输入的,你自己改成题目里的吧
import java.util.HashMap;
import java.util.Map;
public class ListMapDemo
{
//使用map集合存储学生信息
private Map<String,String> map = new HashMap<String, String>();
public ListMapDemo()
{
map.put("100001","张三");
map.put("100002","张四");
map.put("100003","李毅");
map.put("100004","和阿里");
map.put("100005","卡回家");
map.put("100006","尽快哈");
}
/**
* 打印是否有某个学生
* @param name
*/
public void hasStudent(String name)
{
boolean hasName = false;
for(String key : map.keySet())
{
if (name.equals(map.get(key)))
{
hasName = true;
break;
}
}
if (hasName)
{
System.out.println("有姓名为" + name + "的同学");
}
else
{
System.out.println("没有姓名为" + name + "的同学");
}
}
/**
* 获取学生总数量
*/
public int getStudentNum()
{
System.out.println("学生总数量为 = " + map.size());
return map.size();
}
}
-----------------------------------------------------------
public class Test
{
public static void main(String[] args)
{
ListMapDemo listMapDemo = new ListMapDemo();
listMapDemo.hasStudent("张三");
listMapDemo.hasStudent("李四");
listMapDemo.getStudentNum();
}
}