2024-12-05 08:54:54 +08:00

44 lines
1023 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}