public class Card implements Comparable{
String num;
String color;
Card(String color,String num){
this.num=num;
this.color=color;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((num == null) ? 0 : num.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Card))
return false;
Card other = (Card) obj;
if (num == null) {
if (other.num != null)
return false; }
else if (!num.equals(other.num))
return false;
return true;
}
@Override
public int compareTo(Object o) {
//如果数字相同的话就按照花色来排序
if(this.num.compareTo(num)==0) {
return this.color.compareTo(color);
}
return this.num.compareTo(num);
}
}
import java.util.ArrayList;import java.util.List;
public class Player {
int id;
String name;
List<Card>holdCard=new ArrayList<Card>();
Player(int id,String name){
this.id=id;
this.name=name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Player))
return false;
Player other = (Player) obj;
if (name == null) {
if (other.name != null)
return false;
//调用名字来比对
} else if (!name.equals(other.name))
return false;
return true;
}