44 lines
1023 B
Java
44 lines
1023 B
Java
package chapter6.demo64;
|
||
|
||
// Card.java - 扑克牌类
|
||
public class Card implements Comparable<Card> {
|
||
private final String color; // 花色
|
||
private final String point; // 点数
|
||
private final int index; // 编号
|
||
|
||
/**
|
||
* 构造一张扑克牌
|
||
* @param color 花色
|
||
* @param point 点数
|
||
* @param index 编号
|
||
*/
|
||
public Card(String color, String point, int index) {
|
||
this.color = color;
|
||
this.point = point;
|
||
this.index = index;
|
||
}
|
||
|
||
@Override
|
||
public String toString() {
|
||
return color + point;
|
||
}
|
||
|
||
@Override
|
||
public int compareTo(Card other) {
|
||
// if (this.index == other.index) {
|
||
// return 0;
|
||
// } else if (this.index > other.index) {
|
||
// return 1;
|
||
// } else {
|
||
// return -1;
|
||
// }
|
||
// 谁的index小,谁排在前面
|
||
return this.index - other.index;
|
||
}
|
||
|
||
// getter方法
|
||
public int getIndex() {
|
||
return index;
|
||
}
|
||
}
|