做道题吧,顺便分享个段子

点击上方蓝色文字,获取更多推文。


使用Map接口的实现类完成员工工资(姓名-工资)的摸拟:
    1)、添加几条信息
    2)、列出所有的员工姓名
    3)、列出所有员工姓名及其工资
    4)、删除名叫“Tom”的员工信息
    5)、输出Jack的工资,并将其工资改为1500元
    6)、将所有工资低于1000元的员工的工资上涨20%

package HomeworkThree;


import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;


public class HomeworkOne {
  public static void main(String[] arg) {
    Map<Integer, Employee> map = new HashMap<Integer, Employee>();
    map.put(1, new Employee("张三", 30000));
    map.put(2, new Employee("李四", 626));
    map.put(3, new Employee("王五", 20651));
    map.put(4, new Employee("Tom", 206));
    for (Map.Entry<Integer, Employee> item : map.entrySet()) {
      System.out.println("员工编号:" + item.getKey() + "   " + "员工姓名:" + item.getValue().getName());
    }
    for (Entry<Integer, Employee> item : map.entrySet()) {
      System.out.println("员工姓名:" + item.getValue().getName() + "   " + "员工工资:" + item.getValue().getSolary());
    }
    // 删除名叫“Tom”的员工信息
    System.out.println("=======删除名叫“Tom”的员工信息=====");
    for (Entry<Integer, Employee> item : map.entrySet()) {
      if (item.getValue().getName().equals("Tom")) {
        int key = item.getKey();
        map.remove(key);
      }
    }
    System.out.println(map);
    // 输出王五的工资,并将其工资改为1500元
    System.out.println("===========输出王五的工资,并将其工资改为1500元==========");
    for (Entry<Integer, Employee> item : map.entrySet()) {
      if (item.getValue().getName().equals("王五")) {
        int key = item.getKey();
        map.put(key, new Employee("王五", 1500));
        System.out.println("王五的工资:" + item.getValue().getSolary());
      }
    }
    // 将所有工资低于1000元的员工的工资上涨20%
    System.out.println("============将所有工资低于1000元的员工的工资上涨20%==============");
    for (Entry<Integer, Employee> item : map.entrySet()) {
      if (item.getValue().getSolary() < 1000) {
        item.getValue().setSolary(item.getValue().getSolary() + (item.getValue().getSolary() * 20) / 100);
        System.out.println(item);
      }
    }
  }


  private static Employee Employee(String string, int i) {
    // TODO Auto-generated method stub
    return null;
  }
}








class Employee<Stirng, Integer> {
  private String name;
  private int solary;


  public Employee() {
  }


  public Employee(String name, int solary) {
    this.name = name;
    this.solary = solary;
  }


  public String getName() {
    return name;
  }


  public void setName(String name) {
    this.name = name;
  }


  public int getSolary() {
    return solary;
  }


  public void setSolary(int solary) {
    this.solary = solary;
  }


  @Override
  public String toString() {
    return "employee [name=" + name + ", solary=" + solary + "]";
  }


}

最后,一首歌送给大家

家人们,动一动你们的小手,右下方点赞点关注

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值