Write a program that basically simulates a poker game.
You need to implement:
Card class
type: spades, diamond, club, heart
value: A, 2, 3, ..., J, Q, K (you can use 1 to 13)
a constructor to set the type and value
getType, getValue
CompareTo(Card anotherCard)
// compare the value first
// if they are equal, compare the type(spades > diamond > club > heart)
toString() // type and value in the range 1 to 13 if you use integer
Player class
player's name
an array of 5 cards
giveCard(Card p) // give a card to this player
getMaxIndex() // get the index of the maximum card
getCardByIndex(int i) // get cards[i]
toString()
PokerGame class
Test your previous two classes. There is no extra credits for those who write a friendly UI using Scanner class.
1. Create a set of cards(52 cards without joker, use loop to assign the values and types)
2. Create 2 players
3. Give each player 5 cards randomly, print out the cards of each player by calling toString()
4. Get the max card of each player and compare
Hints:
1. You may use an array of 52 length to mark if the corresponding card is given out.
2. Use the following code to generate a random number if you need.
Random rand = new Random();
int num = rand.nextInt(10); // returns a integer from 0 to 9
System.out.println((num+1));
You can add more data members and methods in your classes if you think they are helpful. But you may lose credits if they are harmful to your structure of the class.
Please send your program to xusun09@gmail.com no later than 6:00pm today, and use "CSCE145-LABTEST2-NAME" as the subject.
Tuesday, October 27, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment