PlayingCard.java to demonstrates the use of enumerated types using Card Game:
//************************************************************************
// PlayingCard.java
//
// Demonstrates the use of enumerated types using Card Game
//************************************************************************
public class PlayingCards
{
public enum Rank{Joker, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King};
public static void main(String[] args)
{
Rank highCard, faceCard, card1, card2;
highCard = Rank.Ace;
faceCard = Rank.Queen;
card1 = Rank.Two;
card2 = Rank.Nine;
System.out.println("A blackjack hand: " + highCard + " and " + faceCard);
System.out.println ();
System.out.println("card1 name: " + card1);
System.out.println("card1 face value: " + card1.ordinal());
System.out.println ();
System.out.println ("card2 name: " + card2);
System.out.println ("card2 face value: " + card2.ordinal());
System.out.println ();
System.out.println("A two card hand: " + card1 + " and " + card2);
System.out.println("Hand value: " + (card1.ordinal() + card2.ordinal()));
}
}
No comments:
Post a Comment