a63461612 2017-03-25 13:39 采纳率: 0%
浏览 1444

Map封装,会的来。求封装

public static void main(String[] args) {

    Map<Integer, String> QY = new HashMap<Integer,String>(); 
        QY.put(1, "JN");
        QY.put(2, "QD");
        QY.put(3, "YT");
        QY.put(4, "WH");
        QY.put(5, "RZ");
        QY.put(6, "RZ");
        QY.put(7, "RZ");
        QY.put(8, "RZ");
        QY.put(9, "RZ");
        QY.put(10, "RZ");
    Map<Integer, String> ZJ = new HashMap<Integer,String>();
        ZJ.put(1, "JN");
        ZJ.put(2, "QD");
        ZJ.put(3, "YT");
        ZJ.put(4, "WH");
        ZJ.put(5, "RZ");
        ZJ.put(6, "WH");
        ZJ.put(7, "WH");
        ZJ.put(8, "QD");                                //测试数据用
        Map<Integer, Integer> RECORD = new HashMap<Integer, Integer>();  
        Map<Integer, String> TEMPZJ = new HashMap<Integer, String>();
        Map<Integer, String> TEMPDATA = new HashMap<Integer, String>();
        TEMPZJ.putAll(ZJ); 
        TEMPDATA.putAll(ZJ); 
        for (Map.Entry<Integer, String> entry : QY.entrySet())   //遍历企业
            {  
                 /*  System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());*/
            for (Map.Entry<Integer, String> entry1 : TEMPZJ.entrySet())
                {
                Integer[] keys = TEMPZJ.keySet().toArray(new Integer[0]);
                Random random = new Random();
                Integer randomKey = keys[random.nextInt(keys.length)];
                String randomValue = TEMPZJ.get(randomKey);         //随机专家,得到专家所属区域;  
                if(TEMPZJ.get(randomKey).equals(entry.getValue()))
                { 
                    continue;
                }
                else
                {
                    RECORD.put((entry.getKey()),randomKey);     //企业ID和专家ID存放RECORD,代表分配企业专家
                    TEMPDATA.remove(randomKey);     //删除此条临时存放专家信息,避免重复分配
                    if(TEMPDATA==null || TEMPDATA.size()<1)  
                    {
                        TEMPDATA.putAll(ZJ);        //将专家的数据重新传到TEMPDATA中,避免专家资源短缺问题
                    }
                    else
                    {

                    }
                }
                }
             }  
        for (Integer key : RECORD.keySet()) {

            System.out.println("企业ID="+ key + " and 专家ID= " + RECORD.get(key));

           }
  • 写回答

1条回答 默认 最新

  • devmiao 2017-03-25 13:41
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试