学习常量:public static final 后要大写字母.
public class Card {
/**
* 打牌案例 :斗地主 toString():返回对象文本描述
*/
private int suit;// 花色
private int rank;// 点数
public static final int THREE = 0;// 从3开始,A和2最大.
public static final int FOUR = 1;
public static final int FIVE = 2;
public static final int SIX = 3;
public static final int SEVEN = 4;
public static final int EIGHT = 5;
public static final int NINE = 6;
public static final int TEN = 7;
public static final int JACK = 8;
public static final int QUEEN = 9;
public static final int KING = 10;// K
public static final int ACE = 11;// A
public static final int AEUCE = 12;// 2
public static final int BLACK = 13;// 小王
public static final int COLOR = 14;
/** 方块
*/
public static final int DIAMOND = 0;
/** 梅花
*/
public static final int CLUB = 1;
/**红桃*/
public static final int HEART = 2;
/**黑桃 */
public static final int SPADE = 3;
/**王 */
public static final int JOKER = 4;
public Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
}
public int getSuit() {
return suit;
}
public void setSuit(int suit) {
this.suit = suit;
}
public int getRank() {
return rank;
}
public void setRank(int rand) {
this.rank = rank;
}
public String toString() {
// suit =3 rank =11 算法转换:黑桃A
return suitName[suit] + rankName[rank];
}
private static String[] suitName = { "方块", "梅花", "红桃", "黑桃" };
private static String[] rankName = { "3", "4", "5", "6", "7", "8", "9",
"10", "J", "Q", "K", "A", "2", "小王", "大王" };
public boolean equals(Object obj){//重写equals父类
if(obj==null){return false;}
if(this==obj){//表示同一个对象
return true;
}
if(obj instanceof Card){
Card other = (Card)obj;
return this.rank==other.rank&&this.suit==other.suit;
}
return false;
}
public int hashCode(){//equals要重写.同时也要重写出:hashCode
return suit*100+rank;//c1(rank=12,suit=1) hashCode()=112
}
}
public class Card {
/**
* 打牌案例 :斗地主 toString():返回对象文本描述
*/
private int suit;// 花色
private int rank;// 点数
public static final int THREE = 0;// 从3开始,A和2最大.
public static final int FOUR = 1;
public static final int FIVE = 2;
public static final int SIX = 3;
public static final int SEVEN = 4;
public static final int EIGHT = 5;
public static final int NINE = 6;
public static final int TEN = 7;
public static final int JACK = 8;
public static final int QUEEN = 9;
public static final int KING = 10;// K
public static final int ACE = 11;// A
public static final int AEUCE = 12;// 2
public static final int BLACK = 13;// 小王
public static final int COLOR = 14;
/** 方块
*/
public static final int DIAMOND = 0;
/** 梅花
*/
public static final int CLUB = 1;
/**红桃*/
public static final int HEART = 2;
/**黑桃 */
public static final int SPADE = 3;
/**王 */
public static final int JOKER = 4;
public Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
}
public int getSuit() {
return suit;
}
public void setSuit(int suit) {
this.suit = suit;
}
public int getRank() {
return rank;
}
public void setRank(int rand) {
this.rank = rank;
}
public String toString() {
// suit =3 rank =11 算法转换:黑桃A
return suitName[suit] + rankName[rank];
}
private static String[] suitName = { "方块", "梅花", "红桃", "黑桃" };
private static String[] rankName = { "3", "4", "5", "6", "7", "8", "9",
"10", "J", "Q", "K", "A", "2", "小王", "大王" };
public boolean equals(Object obj){//重写equals父类
if(obj==null){return false;}
if(this==obj){//表示同一个对象
return true;
}
if(obj instanceof Card){
Card other = (Card)obj;
return this.rank==other.rank&&this.suit==other.suit;
}
return false;
}
public int hashCode(){//equals要重写.同时也要重写出:hashCode
return suit*100+rank;//c1(rank=12,suit=1) hashCode()=112
}
}