import java.util.ArrayList;
public class dispatchCard {
private static ArrayList<String> card = new ArrayList<String>();
static final int PEOPLE_COUNT = 7;
/**
* @param args
*/
public static void main(String[] args) {
// generate a sorted list of cards
newCards();
// exchange Cards to get a random list of cards
exchangeCards(50);
// dispatch cards
ArrayList<ArrayList<String>> list = dispatch();
// output every people's cards
output(list);
}
/**
* a random list of cards
*/
private static ArrayList<ArrayList<String>> dispatch() {
ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
int pageCount = card.size() / PEOPLE_COUNT;
int residue = card.size() % PEOPLE_COUNT;
for(int i=0; i < PEOPLE_COUNT;i++){
ArrayList<String> each = new ArrayList<String>();
for(int j=0; j < pageCount;j++){
each.add(card.get(i*pageCount + j));
}
if(i < residue){
each.add(card.get(pageCount * PEOPLE_COUNT + i));
}
sort(each);
list.add(each);
}
return list;
}
/**
* sort cards
*/
private static void sort(ArrayList<String> each) {
for(int i=0; i < each.size();i++){
for(int j=0; j < each.size() - i - 1;j++){
if(each.get(j).compareTo(each.get(j + 1)) < 0){
String tmp = each.get(j);
each.set(j, each.get(j+1));
each.set(j + 1, tmp);
}
}
}
}
/**
* a random list of cards
*/
private static void exchangeCards(int exchageTimes) {
for (int i = 0; i < exchageTimes; i++) {
int r1 = (int) (Math.random() * card.size());
int r2 = (int) (Math.random() * card.size());
String tmp = card.get(r1);
card.set(r1, card.get(r2));
card.set(r2, tmp);
}
}
/**
* a sorted list of cards
*/
private static void newCards() {
// four types
String[] card1 = { "A", "B", "C", "D" };
// 13 pages for every type
String[] card2 = { "03", "04", "05", "06", "07", "08", "09", "10",
"11", "12", "13", "21", "22"};
// input fixed value to the list
for (int i = 0; i <= 3; i++) {
for (int j = 0; j <= 12; j++) {
card.add(card1[i] + ":" + card2[j]);
}
}
}
/**
* output every people's cards
*/
private static void output(ArrayList<ArrayList<String>> list) {
for(ArrayList<String> each : list){
for(String s : each){
System.out.print(s);
System.out.print(",");
}
System.out.println();
}
}
}