我的目标是让最终输出显示卡片套装和卡片等级的字符串,而不是其整数值。我知道我应该调用持有String值的方法,但是如何做到这一点是我的头疼。任何建议都将受到高度赞赏。请注意我是编程的绝对初学者。这是我的代码:
public class Card {
private final int suit, rank;
public static final int DIAMONDS = 1;
public static final int HEARTS = 2;
public static final int CLUBS = 3;
public static final int SPADES = 4;
public static final int ACES = 1;
public static final int DEUCE = 2;
public static final int THREE = 3;
public static final int FOUR = 4;
public static final int FIVE = 5;
public static final int SIX = 6;
public static final int SEVEN = 7;
public static final int EIGHT = 8;
public static final int NINE = 9;
public static final int TEN =10;
public static final int JACKS = 11;
public static final int QUEENS = 12;
public static final int KINGS = 13 ;
public Card (int rank, int suit)
{
this.rank = rank;
this.suit = suit;
}
public int getSuit()
{
return suit;
}
public int getCard()
{
return rank;
}
public static boolean checkSuit(int suit)
{
return DIAMONDS<=suit && suit<=SPADES;
}
public static boolean cheakRank(int rank)
{
return ACES <= rank && rank <= KINGS;
}
public static String rankCard(int rank)
{
switch(rank)
{
case ACES:
return "Ace";
case DEUCE:
return "Deuce";
case THREE:
return "Three";
case FOUR:
return "Four";
case FIVE:
return "Five";
case SIX:
return "Six";
case SEVEN:
return "Seven";
case EIGHT:
return "Eight";
case NINE:
return "Nine";
case TEN:
return "Ten";
case JACKS:
return "Jack";
case QUEENS:
return "Queen";
case KINGS:
return "King";
default:
return null;
}
}
public static String suitCard(int suit)
{
switch(suit)
{
case DIAMONDS:
return "Diamonds";
case CLUBS:
return "Clubs";
case HEARTS:
return "Hearts";
case SPADES:
return "Spades";
default:
return null;
}
}
}
我的主要方法是:
public class PokerClass {
public static void main(String[]args)
{
Card pokerCard = new Card(1, 11);
System.out.println("The card is: "+pokerCard.getSuit()+" and a: "+pokerCard.getCard());
}
}