想请教排序问题,按集合中的类的内部类的元素的大小怎么排序
好多讲的都没用上,感觉要重新看一边java入门
package com.lv;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.Collections;
public class CardGame {
Map<Integer,Cards> puKe;
List<People> gamer;
int[] order=new int[53];
public CardGame() {
puKe=new HashMap<Integer,Cards>();
gamer=new ArrayList<People>();
}
public void cardBuild() {
String type1="梅花";
String type2="方块";
String type3="红心";
String type4="黑桃";
String Num="A 2 3 4 5 6 7 8 9 10 J Q k";
String[] NUM=Num.split(" ");
System.out.println(Num.toString());
int h=0;
for(int i=0;i<13;i++) {
Cards c=new Cards();
c.num=NUM[i];
c.type=type1;
puKe.put(h,c);
Cards a=new Cards();
a.num=NUM[i];
h++;
a.type=type2;
puKe.put(h,a);
Cards b=new Cards();
b.num=NUM[i];
h++;
b.type=type3;
puKe.put(h,b);
Cards d=new Cards();
d.num=NUM[i];
h++;
d.type=type4;
puKe.put(h,d);
h++;
}
/*
* for(int i=0;i<13;i++) { Cards c=new Cards(); c.type=type2; c.num=NUM[i];
*
* puKe.put(i+13,c); }
*
* for(int i=0;i<13;i++) { Cards c=new Cards(); c.type=type3; c.num=NUM[i];
*
* puKe.put(i+26,c); } for(int i=0;i<13;i++) { Cards c=new Cards();
* c.type=type4; c.num=NUM[i];
*
* puKe.put(i+39 ,c); }
*/
}
public void cardShow() {
//通过keyset方法,返回Map中的所有建的值
Set<Integer>KeySet=puKe.keySet();
System.out.println("共有:"+KeySet.size()+"张牌;");
//遍历取得每一个建
for(Integer s:KeySet) {
Cards uu=puKe.get(s);
System.out.println(uu.type+"\t "+uu.num);
}
}
public void cardPeopleShow() {
//通过keyset方法,返回Map中的所有建的值
//Set<String>KeySet=gamer.keySet();
System.out.println("创建"+gamer.size()+"个人物;");
//遍历取得每一个建
for(People s:gamer) {
System.out.println(s.ID+"\t "+s.name);
}
}
public void cardSetPeople() {
Scanner input=new Scanner(System.in);
for(int i=1;i<3;i++) {
People player=new People();
System.out.println("请输入玩家"+i+"的ID:");
boolean r=true;
while(r){
r=false;
String id =input.next();
for(People p:gamer) {
if(p.ID.equals(id))
{
System.out.println("该ID已被使用,请重新输入:");
r=true;
break;
}
}
if(r==false) {
player.ID =id;
}
}
System.out.println("请输入玩家"+i+"的姓名:");
boolean e=true;
while(e){
e=false;
String name =input.next();
for(People p:gamer) {
if(p.name.equals(name))
{
System.out.println("该姓名已被使用,请重新输入:");
e=true;
break;
}
}
if(e==false) {
player.name =name;
}
}
gamer.add(player);
}
}
public Integer[] createSolution2(int len)
{ Integer solutionArr[] = new Integer[len];
List list=new ArrayList<Integer>();
for (int i = 0; i < len; i++)
list.add(i+1);
Collections.shuffle(list);
list.toArray(solutionArr);
return solutionArr;
}
public void cardGet(int i) {
Integer[] num=createSolution2 (53);
int max1,max2;
gamer.get(0).card .add(puKe.get(num[4*i]));
gamer.get(1).card .add(puKe.get(num[4*i+1]));
gamer.get(0).card .add(puKe.get(num[4*i+2]));
gamer.get(1).card .add(puKe.get(num[4*i+3]));
for(int j=0;j<2;j++)
{
System.out.print(gamer.get(j).name +"拿牌\t"+gamer.get(j).card .get(0).type+gamer.get(j).card .get(0).num );
System.out.println("\t"+gamer.get(j).card .get(1).type+gamer.get(j).card .get(1).num );
}
if(num[4*i]<num[4*i+2]) {
System.out.println(gamer.get(0).name +"的最大牌为:"+puKe.get(num[4*i+2]).type +puKe.get(num[4*i+2]).num);
max1=num[4*i+2];
}
else{
System.out.println(gamer.get(0).name +"的最大牌为:"+puKe.get(num[4*i]).type +puKe.get(num[4*i]).num);
max1=num[4*i];
}
if(num[4*i+1]<num[4*i+3]) {
System.out.println(gamer.get(0).name +"的最大牌为:"+puKe.get(num[4*i+3]).type +puKe.get(num[4*i+3]).num);
max2=num[4*i+3];
}
else{
System.out.println(gamer.get(0).name +"的最大牌为:"+puKe.get(num[4*i+1]).type +puKe.get(num[4*i+1]).num);
max2=num[4*i+1];
}
if(max1<max2) {
System.out.println(gamer.get(0).name +"获胜");
}
else {
System.out.println(gamer.get(1).name +"获胜");
}
}
/*
* public void cardComparater() {
*
*
* Collections.sort(car,new CardsComparator()); for(Cards c:car) {
* System.out.println(c.type +c.num +"\t"); } }
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CardGame cg=new CardGame();
cg.cardBuild();
cg.cardShow();
cg.cardSetPeople();
cg.cardPeopleShow();
cg.cardGet(1);
//cg.cardComparater();
}
}