<pre name="code" class="java">package carddemo;
class Card {
private Cardtype cardtype;
private Rank rank;
private Color color;
private boolean isJoker;
public Card(Cardtype type, Rank rank) {
this.rank = rank;
this.cardtype = type;
this.isJoker=false;
}
public Card(Cardtype cardtype,Color color) {
this.cardtype=cardtype;
this.color=color;
this.isJoker=true;
}
public void setColor(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
public Cardtype getCardtype() {
return cardtype;
}
public void setCardtype(Cardtype cardtype) {
this.cardtype = cardtype;
}
public Rank getRank() {
return rank;
}
public void setRank(Rank rank) {
this.rank = rank;
}
public enum Cardtype {
HERTS("红桃"), SPADE("黑桃"), DIAMOND("方块"), CLUB("梅花"),JOKER("鬼");
private String string;
private Cardt
java枚举练习
最新推荐文章于 2024-07-22 12:25:44 发布
本文通过一个玩家类的例子,深入探讨了Java中枚举类型的使用,包括枚举的定义、枚举常量的访问以及枚举在实际编程中的应用。
摘要由CSDN通过智能技术生成