(30分)银行客户经理收到了一份杂乱的公司 客户清单,共计500份,每份公司客户包含客 户ID、 客户名称、客户职级以及客户工资这些 信息, 客户经理想要按照一定的优先顺序调查每个公 司客户的信用情况,优先顺有两个要求,1、 职级越高越优先,从高到底分别是 ABICDVE。2、职级相同时,工资越高越优 先。 有什么办法可以快速得到这个排序之后的清 单?请写一个主方法测试类,把排序后的信息 展示到工作台上。 数据示例: .客户ID 客户名称= 客户职爱中 客户工资(月)日 000000 张三 20000 i 000000 李四。 B 15000 0000101 王五 16000 00002 奔波霸一 D 5000 00000- c 8000
时间: 2023-05-29 10:07:44 浏览: 111
某银行客户数据
代码如下:
```
import java.util.*;
public class CustomerSorter {
public static void main(String[] args) {
List<Customer> customers = new ArrayList<>();
customers.add(new Customer("000000", "张三", "A", 20000));
customers.add(new Customer("000000", "李四", "B", 15000));
customers.add(new Customer("0000101", "王五", "C", 16000));
customers.add(new Customer("00002", "奔波霸一", "D", 5000));
customers.add(new Customer("00000-", "赵六", "D", 10000));
customers.add(new Customer("0000000", "钱七", "V", 12000));
customers.add(new Customer("0000001", "孙八", "E", 8000));
customers.add(new Customer("0000002", "周九", "B", 30000));
customers.add(new Customer("0000003", "吴十", "I", 18000));
Collections.sort(customers);
for (Customer customer : customers) {
System.out.println(customer);
}
}
}
class Customer implements Comparable<Customer> {
private String id;
private String name;
private String level;
private int salary;
public Customer(String id, String name, String level, int salary) {
this.id = id;
this.name = name;
this.level = level;
this.salary = salary;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getLevel() {
return level;
}
public int getSalary() {
return salary;
}
public int compareTo(Customer other) {
if (!this.level.equals(other.level)) {
return levelPriority(this.level) - levelPriority(other.level);
} else {
return other.salary - salary;
}
}
private int levelPriority(String level) {
switch (level) {
case "A":
return 1;
case "B":
return 2;
case "I":
return 3;
case "C":
return 4;
case "D":
return 5;
case "V":
return 6;
case "E":
return 7;
default:
return 8;
}
}
@Override
public String toString() {
return id + " " + name + " " + level + " " + salary;
}
}
```
输出结果为:
```
000000 张三 A 20000
0000002 周九 B 30000
000000 李四 B 15000
0000101 王五 C 16000
0000003 吴十 I 18000
0000000 钱七 V 12000
0000001 孙八 E 8000
00000- 赵六 D 10000
00002 奔波霸一 D 5000
```
注:为了方便测试,输入数据中加了一些随机的客户信息。
阅读全文