那个面试题的 有关会员客户积分问题的剩余代码

chengxu2011 2013-01-29 02:23:45
我靠。。。。居然一个用户只能回复3次 我代码还没贴完。那个问面试题求帮助的人剩余代码我放这里了你自己来看吧 主要是比较器和管理和测试的代码:

最后是我的管理类和测试类还有一个比较器:
[code=java]

package com.djk.test;

import java.util.Comparator;

/**
* 比较器
* @author djk
*
*/
public class MyComparator implements Comparator<UserBean>
{

@Override
public int compare(UserBean o1, UserBean o2)
{
UserBean u1 = o1;
UserBean u2 = o2;

if(Double.parseDouble(u1.getLastCode()) > Double.parseDouble(u2.getLastCode()))
{
return 0;
}else if(Double.parseDouble(u1.getLastCode()) == Double.parseDouble(u2.getLastCode()))
{
if(Double.parseDouble(u1.getLastPrice()) > Double.parseDouble(u1.getLastPrice()))
{
return 0;
}else
{
return 1;
}

}else
{
return 1;
}
}

}

package com.djk.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 管理类
* @author djk
*
*/
public class BookManager
{
private Map<String,HandleCode> map = new HashMap<String, HandleCode>();

private HandleFile handleFile;

public BookManager(Map<String,HandleCode> map,HandleFile handleFile)
{
this.map = map;
this.handleFile = handleFile;
}

/**
*
* 输出文件
*/
public void recordResult (String billPath,String recordsPath,String resultPath)
{
Map<String,UserBean> beanMap= handleFile.getUserBean(billPath,recordsPath);

List<UserBean> list = new ArrayList<UserBean>();

for(String key : beanMap.keySet())
{
UserBean userBean = beanMap.get(key);
HandleCode handleCode = map.get(userBean.getBookType());
if(null !=handleCode)
{
String resultCode = handleCode.getHandleCode(userBean);
userBean.setCode(resultCode);
System.out.println("name:"+userBean.getUsername());
double code = Double.parseDouble(userBean.getCode())+Double.parseDouble(userBean.getAlerdyCode());
double price = Double.parseDouble(userBean.getBookPrice())+Double.parseDouble(userBean.getAldedyBill());
userBean.setLastCode(code+"");
userBean.setLastPrice(price+"");
list.add(userBean);
}
}

Collections.sort(list, new MyComparator());
//处理完成以后输出文件
handleFile.recordResult(list,resultPath);
}

public Map<String, HandleCode> getMap()
{
return map;
}

public void setMap(Map<String, HandleCode> map)
{
this.map = map;
}

public HandleFile getHandleFile()
{
return handleFile;
}

public void setHandleFile(HandleFile handleFile)
{
this.handleFile = handleFile;
}

}


package com.djk.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 管理类
* @author djk
*
*/
public class BookManager
{
private Map<String,HandleCode> map = new HashMap<String, HandleCode>();

private HandleFile handleFile;

public BookManager(Map<String,HandleCode> map,HandleFile handleFile)
{
this.map = map;
this.handleFile = handleFile;
}

/**
*
* 输出文件
*/
public void recordResult (String billPath,String recordsPath,String resultPath)
{
Map<String,UserBean> beanMap= handleFile.getUserBean(billPath,recordsPath);

List<UserBean> list = new ArrayList<UserBean>();

for(String key : beanMap.keySet())
{
UserBean userBean = beanMap.get(key);
HandleCode handleCode = map.get(userBean.getBookType());
if(null !=handleCode)
{
String resultCode = handleCode.getHandleCode(userBean);
userBean.setCode(resultCode);
System.out.println("name:"+userBean.getUsername());
double code = Double.parseDouble(userBean.getCode())+Double.parseDouble(userBean.getAlerdyCode());
double price = Double.parseDouble(userBean.getBookPrice())+Double.parseDouble(userBean.getAldedyBill());
userBean.setLastCode(code+"");
userBean.setLastPrice(price+"");
list.add(userBean);
}
}

Collections.sort(list, new MyComparator());
//处理完成以后输出文件
handleFile.recordResult(list,resultPath);
}

public Map<String, HandleCode> getMap()
{
return map;
}

public void setMap(Map<String, HandleCode> map)
{
this.map = map;
}

public HandleFile getHandleFile()
{
return handleFile;
}

public void setHandleFile(HandleFile handleFile)
{
this.handleFile = handleFile;
}
package com.djk.test;

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


/**
* 客户端
* @author djk
*
*/
public class Client
{
public static void main(String[] args)
{
HandleFile handleFile = new DjkHandleFile();
HandleCode computerType = new ComputeType();
HandleCode buildingType = new BuildingType();
HandleCode englishType = new EnglishAndOtherType();
HandleCode economicType = new EconomicAndOtherType();
HandleCode novleType = new NovelAndOtherType();
Map<String, HandleCode> map = new HashMap<String, HandleCode>();
map.put("A", computerType);
map.put("B", buildingType);
map.put("C", englishType);
map.put("D", economicType);
map.put("E", novleType);
BookManager bookManager = new BookManager(map,handleFile);
bookManager.recordResult("D:/bill.txt","D:/records.txt","D:/resuts.txt");
}
}

}



[/code]
...全文
53 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chengxu2011 2013-01-29
自己顶。。。。
  • 打赏
  • 举报
回复
相关推荐
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2013-01-29 02:23
社区公告
暂无公告