求大神帮忙!编写java代码!

写一个部门类DeptVO,包含2个私有属性:deptName(字符串,部门名称)、num(部门人数),及对应get,set方法。用这个部门类创建3个部门对象(财务部、信息技术部、设备管理部),并以部门名称做为key放到map里,通过map取出信息技术部的信息,打印人数。

public class DeptVO {

private String deptName;
private int num;

public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}

}

public class Test {
public static void main(String[] args) {
DeptVO dept1 = new DeptVO();
dept1.setDeptName("财务部");
dept1.setNum(1);
DeptVO dept2 = new DeptVO();
dept2.setDeptName("信息技术部");
dept2.setNum(2);
DeptVO dept3 = new DeptVO();
dept3.setDeptName("设备管理部");
dept3.setNum(3);

Map<String, DeptVO> map = new HashMap<String, DeptVO>();
map.put("财务部", dept1);
map.put("信息技术部", dept2);
map.put("设备管理部", dept3);

DeptVO dept = map.get("信息技术部");
System.out.println("信息技术部的数是:"+dept.getNum());
}
}

温馨提示:答案为网友推荐,仅供参考
相似回答