package com.heima.IO;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.TreeMap;
import java.util.TreeSet;
public class Day1_ClassTest2 {
public static void main(String[] args) {
String[] a = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K",
"A", "2" };
String[] b = { "红桃", "梅花", "方片", "黑桃" };
TreeMap<Integer, String> tm = new TreeMap<>();
int t = 1;
for (String st : a) {
for (String st1 : b) {
tm.put(t++, st1.concat(st));
}
}
tm.put(53, "小王");
tm.put(54, "大王");
ArrayList<Integer> al = new ArrayList<>();
for (int i = 1; i <= 54; i++) {
al.add(i);
}
Collections.shuffle(al);
TreeSet<Integer> 黎玉梅 = new TreeSet<>(new CM());
TreeSet<Integer> 何亚辉 = new TreeSet<>(new CM());
TreeSet<Integer> 阮氏荷 = new TreeSet<>(new CM());
TreeSet<Integer> 底牌 = new TreeSet<>(new CM());
for (int i = 1; i < al.size() - 3; i++) {
if (i % 3 == 0) {
黎玉梅.add(al.get(i));
} else if (i % 3 == 1) {
何亚辉.add(al.get(i));
} else {
阮氏荷.add(al.get(i));
}
}
for (int i = al.size() - 3; i < al.size(); i++) {
底牌.add(al.get(i));
}
show(黎玉梅, tm, "黎玉梅");
show(何亚辉, tm, "何亚辉");
show(阮氏荷, tm, "阮氏荷");
show(底牌, tm, "底牌");
}
public static void show(TreeSet<Integer> ts, TreeMap<Integer, String> tm,
String name) {
System.out.print(name + "的牌面是 ");
for (Integer in : ts) {
System.out.print(tm.get(in));
}
System.out.println();
}
}
class CM implements Comparator<Integer> {
public int compare(Integer i, Integer i1) {
return i1 - i;
}
}
|