package com.homework; import java.util.ArrayList; import java.util.Collections; public class Q4 { public static void main(String[] args) { ArrayList<Pocket> alist = new ArrayList<Pocket>(54); alist.add(new Pocket(3,"mei")); alist.add(new Pocket(3,"hotao")); alist.add(new Pocket(3,"fa")); alist.add(new Pocket(3,"heitao")); alist.add(new Pocket(4,"mei")); alist.add(new Pocket(4,"hotao")); alist.add(new Pocket(4,"fa")); alist.add(new Pocket(4,"heitao")); alist.add(new Pocket(5,"mei")); alist.add(new Pocket(5,"hotao")); alist.add(new Pocket(5,"fa")); alist.add(new Pocket(5,"heitao")); alist.add(new Pocket(6,"mei")); alist.add(new Pocket(6,"hotao")); alist.add(new Pocket(6,"fa")); alist.add(new Pocket(6,"heitao")); alist.add(new Pocket(7,"mei")); alist.add(new Pocket(7,"hotao")); alist.add(new Pocket(7,"fa")); alist.add(new Pocket(7,"heitao")); alist.add(new Pocket(8,"mei")); alist.add(new Pocket(8,"hotao")); alist.add(new Pocket(8,"fa")); alist.add(new Pocket(8,"heitao")); alist.add(new Pocket(9,"mei")); alist.add(new Pocket(9,"hotao")); alist.add(new Pocket(9,"fa")); alist.add(new Pocket(9,"heitao")); alist.add(new Pocket(10,"mei")); alist.add(new Pocket(10,"hotao")); alist.add(new Pocket(10,"fa")); alist.add(new Pocket(10,"heitao")); alist.add(new Pocket(11,"mei")); alist.add(new Pocket(11,"hotao")); alist.add(new Pocket(11,"fa")); alist.add(new Pocket(11,"heitao")); alist.add(new Pocket(12,"mei")); alist.add(new Pocket(12,"hotao")); alist.add(new Pocket(12,"fa")); alist.add(new Pocket(12,"heitao")); alist.add(new Pocket(13,"mei")); alist.add(new Pocket(13,"hotao")); alist.add(new Pocket(13,"fa")); alist.add(new Pocket(13,"heitao")); alist.add(new Pocket(14,"mei")); alist.add(new Pocket(14,"hotao")); alist.add(new Pocket(14,"fa")); alist.add(new Pocket(14,"heitao")); alist.add(new Pocket(15,"mei")); alist.add(new Pocket(15,"hotao")); alist.add(new Pocket(15,"fa")); alist.add(new Pocket(15,"heitao")); alist.add(new Pocket(16,"mei")); alist.add(new Pocket(16,"hotao")); ArrayList<Pocket> zhansan = new ArrayList<Pocket>(20); ArrayList<Pocket> lishi = new ArrayList<Pocket>(20); ArrayList<Pocket> wangwu = new ArrayList<Pocket>(20); Collections.shuffle(alist); for(int i = 1 ; i <= alist.size()-3 ; i++){ switch(i%3){ case 1 : zhansan.add(alist.get(i-1));break; case 2 : lishi.add(alist.get(i-1));break; case 0 : wangwu.add(alist.get(i-1));break; } } Collections.sort(zhansan); for(Pocket p : zhansan){ System.out.print(p); } System.out.println("\n----------------------------------------------"); Collections.sort(lishi); for(Pocket p : lishi){ System.out.print(p); } System.out.println("\n----------------------------------------------"); Collections.sort(wangwu); for(Pocket p : wangwu){ System.out.print(p); } } }