集合 员工薪水管理

import java.util.HashMap;
import java.util.Iterator;
import  java.util.Map;

class Employee{
private  String  id;
private String  name;
private  double  salary=2000;

public void setSalary(double salary){
this.salary=salary;

}
public double  getSalary(){
return  salary;
}

public void setID(String id){
this.id=id;
}
public void setName(String name){
this.name=name;
}
public String getID(){
return id;
}
public String getName(){
return name;
}

public Employee(String id,String name){
this.id=id;
this.name=name;

}

public String show(){
String sal=String.valueOf(salary);
return  name+"\t"+"员工号"+id+"\t"+"工资"+sal;
}

}

public class play32 {


public static void main(String[] args) {
// TODO Auto-generated method stub
Employee  e1=new Employee("001","11tom");
Employee  e2=new Employee("002","22tom");
Employee  e3=new Employee("003","33tom");
Employee  e4=new Employee("004","44tom");

Map employee=new HashMap();

employee.put("0001", e1);
employee.put("0002", e2);
employee.put("0003", e3);
employee.put("0004", e4);

//显示员工号为0004员工的信息
System.out.println( ((Employee) employee.get("0004")).show());

//显示所有员工的信息
System.out.println("所有员工的信息如下");
Iterator it=employee.keySet().iterator();
while(it.hasNext()){
System.out.println(((Employee) employee.get(it.next())).show());

//修改员工号为0002的工资为3000
System.out.println("修改员工信息");
Employee  employees=(Employee) employee.get("0002");
employees.setSalary(3000);
System.out.println(((Employee)employee).show());

employee.remove("0003");

System.out.println("删除员工后,剩余员工的信息");
it=employee.keySet().iterator();
while(it.hasNext()){
System.out.println(((Employee)employee.get(it.next())).show());

}


}
}


}


红色显错误Exception in thread "main" java.lang.ClassCastException: java.util.HashMap cannot be cast to first.Employee
at first.play32.main(play32.java:78)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值