Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSC220 Programming Project#4 ============================ Due Date: 11:55pm, Sun

ID: 3835300 • Letter: C

Question

CSC220 Programming Project#4
============================

Due Date: 11:55pm, Sunday, 5/14 *** No late projects will be accepted ****

- Upload a zip file, including PlayingCard.java and VideoPoker.java, to ilearn

- Implement poker game program in package PJ4:

Part I (40%) Implement Decks class
Part II (60%) Implement VideoPoker class

Bonus (30%) Add GUI, only after you have completed I & II
Must complete by same due date.
Submit both non-GUI and GUI versions

See PJ4/PlayingCard.java and PJ4/VideoPoker.java for more info.

- Use TestVideoPoker.java to test correctness of your program

- Compile programs (you are in directory containing Readme file):
  
javac PJ4/*.java
javac TestVideoPoker.java

- Run programs (you are in directory containing Readme file):

// Run tests in PJ4 classes
java PJ4.Decks
java PJ4.VideoPoker

// Run main test program
java TestVideoPoker


******************************************************************************************
  
- Sample output : java PJ4.Decks


******* Create 2 decks of cards ********

getNumberDecks:2
getWithJokers:true

************************************************

Loop # 0

Before shuffle:108 cards

   [Joker #1, Joker #1, A Clubs, 2 Clubs, 3 Clubs, 4 Clubs, 5 Clubs, 6 Clubs, 7 Clubs, 8 Clubs, 9 Clubs, 10 Clubs, J Clubs, Q Clubs, K Clubs, A Diamonds, 2 Diamonds, 3 Diamonds, 4 Diamonds, 5 Diamonds, 6 Diamonds, 7 Diamonds, 8 Diamonds, 9 Diamonds, 10 Diamonds, J Diamonds, Q Diamonds, K Diamonds, A Hearts, 2 Hearts, 3 Hearts, 4 Hearts, 5 Hearts, 6 Hearts, 7 Hearts, 8 Hearts, 9 Hearts, 10 Hearts, J Hearts, Q Hearts, K Hearts, A Spades, 2 Spades, 3 Spades, 4 Spades, 5 Spades, 6 Spades, 7 Spades, 8 Spades, 9 Spades, 10 Spades, J Spades, Q Spades, K Spades, Joker #1, Joker #1, A Clubs, 2 Clubs, 3 Clubs, 4 Clubs, 5 Clubs, 6 Clubs, 7 Clubs, 8 Clubs, 9 Clubs, 10 Clubs, J Clubs, Q Clubs, K Clubs, A Diamonds, 2 Diamonds, 3 Diamonds, 4 Diamonds, 5 Diamonds, 6 Diamonds, 7 Diamonds, 8 Diamonds, 9 Diamonds, 10 Diamonds, J Diamonds, Q Diamonds, K Diamonds, A Hearts, 2 Hearts, 3 Hearts, 4 Hearts, 5 Hearts, 6 Hearts, 7 Hearts, 8 Hearts, 9 Hearts, 10 Hearts, J Hearts, Q Hearts, K Hearts, A Spades, 2 Spades, 3 Spades, 4 Spades, 5 Spades, 6 Spades, 7 Spades, 8 Spades, 9 Spades, 10 Spades, J Spades, Q Spades, K Spades]

==============================================

After shuffle:108 cards

   [A Diamonds, 8 Clubs, 6 Diamonds, 8 Diamonds, K Spades, 6 Clubs, K Spades, 10 Diamonds, 6 Hearts, 2 Spades, J Spades, J Hearts, A Diamonds, 10 Hearts, 3 Clubs, J Diamonds, 2 Hearts, 3 Spades, 8 Hearts, J Clubs, 4 Spades, A Hearts, K Hearts, Joker #1, 5 Diamonds, 10 Hearts, 5 Clubs, 4 Diamonds, A Clubs, J Hearts, A Spades, 7 Spades, 7 Diamonds, 3 Diamonds, 7 Spades, 4 Hearts, 7 Clubs, 5 Diamonds, A Hearts, Q Spades, Joker #1, A Spades, J Diamonds, K Hearts, 9 Spades, 4 Spades, 9 Diamonds, 9 Hearts, Joker #1, 5 Hearts, Q Clubs, K Clubs, 9 Diamonds, 5 Spades, 9 Hearts, 5 Clubs, 2 Clubs, 5 Spades, 8 Clubs, 8 Spades, 9 Spades, 2 Diamonds, 10 Clubs, 3 Hearts, 5 Hearts, K Clubs, 3 Diamonds, 10 Diamonds, Q Spades, 2 Clubs, 4 Diamonds, 6 Spades, Joker #1, 6 Hearts, 4 Hearts, 2 Hearts, 8 Hearts, 2 Spades, 7 Diamonds, 10 Spades, Q Diamonds, Q Clubs, 7 Hearts, Q Hearts, 8 Diamonds, 4 Clubs, K Diamonds, 8 Spades, K Diamonds, J Spades, 10 Clubs, A Clubs, 7 Hearts, 6 Spades, 3 Spades, J Clubs, Q Diamonds, 9 Clubs, 6 Diamonds, 6 Clubs, 10 Spades, 3 Hearts, 3 Clubs, 4 Clubs, 7 Clubs, 9 Clubs, Q Hearts, 2 Diamonds]


Hand 0:27 cards

   [Q Clubs, 7 Hearts, Q Hearts, 8 Diamonds, 4 Clubs, K Diamonds, 8 Spades, K Diamonds, J Spades, 10 Clubs, A Clubs, 7 Hearts, 6 Spades, 3 Spades, J Clubs, Q Diamonds, 9 Clubs, 6 Diamonds, 6 Clubs, 10 Spades, 3 Hearts, 3 Clubs, 4 Clubs, 7 Clubs, 9 Clubs, Q Hearts, 2 Diamonds]


Remain:81 cards

   [A Diamonds, 8 Clubs, 6 Diamonds, 8 Diamonds, K Spades, 6 Clubs, K Spades, 10 Diamonds, 6 Hearts, 2 Spades, J Spades, J Hearts, A Diamonds, 10 Hearts, 3 Clubs, J Diamonds, 2 Hearts, 3 Spades, 8 Hearts, J Clubs, 4 Spades, A Hearts, K Hearts, Joker #1, 5 Diamonds, 10 Hearts, 5 Clubs, 4 Diamonds, A Clubs, J Hearts, A Spades, 7 Spades, 7 Diamonds, 3 Diamonds, 7 Spades, 4 Hearts, 7 Clubs, 5 Diamonds, A Hearts, Q Spades, Joker #1, A Spades, J Diamonds, K Hearts, 9 Spades, 4 Spades, 9 Diamonds, 9 Hearts, Joker #1, 5 Hearts, Q Clubs, K Clubs, 9 Diamonds, 5 Spades, 9 Hearts, 5 Clubs, 2 Clubs, 5 Spades, 8 Clubs, 8 Spades, 9 Spades, 2 Diamonds, 10 Clubs, 3 Hearts, 5 Hearts, K Clubs, 3 Diamonds, 10 Diamonds, Q Spades, 2 Clubs, 4 Diamonds, 6 Spades, Joker #1, 6 Hearts, 4 Hearts, 2 Hearts, 8 Hearts, 2 Spades, 7 Diamonds, 10 Spades, Q Diamonds]

==============================================

After shuffle:81 cards

   [J Spades, 3 Hearts, 10 Spades, 3 Spades, J Diamonds, Q Spades, 8 Hearts, 2 Diamonds, 9 Diamonds, 10 Clubs, K Spades, 5 Diamonds, 6 Hearts, 4 Diamonds, 9 Spades, 6 Spades, Q Clubs, A Clubs, A Diamonds, 9 Hearts, J Diamonds, 2 Spades, 7 Diamonds, 8 Clubs, 4 Diamonds, 9 Hearts, 9 Diamonds, 7 Spades, 5 Hearts, 10 Diamonds, J Clubs, Q Spades, 10 Diamonds, Joker #1, 5 Spades, 9 Spades, 8 Diamonds, 5 Diamonds, 2 Spades, 4 Hearts, 10 Hearts, 4 Spades, 6 Diamonds, A Diamonds, 2 Hearts, J Hearts, 5 Clubs, 3 Diamonds, 3 Diamonds, Q Diamonds, 3 Clubs, K Spades, 2 Clubs, 7 Diamonds, 2 Clubs, A Spades, 4 Hearts, 7 Spades, Joker #1, 10 Hearts, A Hearts, 4 Spades, 8 Spades, K Hearts, 6 Clubs, 7 Clubs, K Hearts, K Clubs, 5 Spades, 5 Hearts, 6 Hearts, 2 Hearts, A Spades, 8 Hearts, J Hearts, Joker #1, A Hearts, 8 Clubs, Joker #1, 5 Clubs, K Clubs]


Hand 1:27 cards

   [2 Clubs, A Spades, 4 Hearts, 7 Spades, Joker #1, 10 Hearts, A Hearts, 4 Spades, 8 Spades, K Hearts, 6 Clubs, 7 Clubs, K Hearts, K Clubs, 5 Spades, 5 Hearts, 6 Hearts, 2 Hearts, A Spades, 8 Hearts, J Hearts, Joker #1, A Hearts, 8 Clubs, Joker #1, 5 Clubs, K Clubs]


Remain:54 cards

   [J Spades, 3 Hearts, 10 Spades, 3 Spades, J Diamonds, Q Spades, 8 Hearts, 2 Diamonds, 9 Diamonds, 10 Clubs, K Spades, 5 Diamonds, 6 Hearts, 4 Diamonds, 9 Spades, 6 Spades, Q Clubs, A Clubs, A Diamonds, 9 Hearts, J Diamonds, 2 Spades, 7 Diamonds, 8 Clubs, 4 Diamonds, 9 Hearts, 9 Diamonds, 7 Spades, 5 Hearts, 10 Diamonds, J Clubs, Q Spades, 10 Diamonds, Joker #1, 5 Spades, 9 Spades, 8 Diamonds, 5 Diamonds, 2 Spades, 4 Hearts, 10 Hearts, 4 Spades, 6 Diamonds, A Diamonds, 2 Hearts, J Hearts, 5 Clubs, 3 Diamonds, 3 Diamonds, Q Diamonds, 3 Clubs, K Spades, 2 Clubs, 7 Diamonds]

==============================================

After shuffle:54 cards

   [6 Diamonds, 4 Spades, A Clubs, 2 Spades, 5 Clubs, 10 Clubs, 9 Spades, 5 Hearts, A Diamonds, A Diamonds, 5 Diamonds, Q Spades, 8 Hearts, 10 Hearts, K Spades, 2 Diamonds, 9 Diamonds, 10 Spades, 3 Diamonds, 6 Spades, J Diamonds, Q Clubs, 6 Hearts, 4 Diamonds, 8 Clubs, 7 Diamonds, 4 Diamonds, Q Diamonds, J Clubs, 10 Diamonds, 9 Diamonds, 4 Hearts, 3 Diamonds, 3 Clubs, 8 Diamonds, 9 Hearts, 2 Spades, 7 Diamonds, 7 Spades, 5 Spades, J Spades, J Hearts, 3 Spades, 5 Diamonds, J Diamonds, Q Spades, 9 Spades, K Spades, 10 Diamonds, 3 Hearts, Joker #1, 2 Clubs, 2 Hearts, 9 Hearts]


Hand 2:27 cards

   [Q Diamonds, J Clubs, 10 Diamonds, 9 Diamonds, 4 Hearts, 3 Diamonds, 3 Clubs, 8 Diamonds, 9 Hearts, 2 Spades, 7 Diamonds, 7 Spades, 5 Spades, J Spades, J Hearts, 3 Spades, 5 Diamonds, J Diamonds, Q Spades, 9 Spades, K Spades, 10 Diamonds, 3 Hearts, Joker #1, 2 Clubs, 2 Hearts, 9 Hearts]


Remain:27 cards

   [6 Diamonds, 4 Spades, A Clubs, 2 Spades, 5 Clubs, 10 Clubs, 9 Spades, 5 Hearts, A Diamonds, A Diamonds, 5 Diamonds, Q Spades, 8 Hearts, 10 Hearts, K Spades, 2 Diamonds, 9 Diamonds, 10 Spades, 3 Diamonds, 6 Spades, J Diamonds, Q Clubs, 6 Hearts, 4 Diamonds, 8 Clubs, 7 Diamonds, 4 Diamonds]

==============================================

After shuffle:27 cards

   [A Clubs, 6 Hearts, 4 Diamonds, 8 Hearts, J Diamonds, 10 Clubs, 2 Spades, 7 Diamonds, Q Clubs, 4 Spades, 6 Spades, 2 Diamonds, Q Spades, 8 Clubs, 6 Diamonds, 5 Clubs, A Diamonds, 10 Spades, 4 Diamonds, 10 Hearts, 5 Hearts, 9 Diamonds, 9 Spades, 3 Diamonds, A Diamonds, 5 Diamonds, K Spades]


Hand 3:27 cards

   [A Clubs, 6 Hearts, 4 Diamonds, 8 Hearts, J Diamonds, 10 Clubs, 2 Spades, 7 Diamonds, Q Clubs, 4 Spades, 6 Spades, 2 Diamonds, Q Spades, 8 Clubs, 6 Diamonds, 5 Clubs, A Diamonds, 10 Spades, 4 Diamonds, 10 Hearts, 5 Hearts, 9 Diamonds, 9 Spades, 3 Diamonds, A Diamonds, 5 Diamonds, K Spades]


Remain:0 cards

   []

==============================================

After shuffle:0 cards

   []


Hand 4:27 cards
*** In catch block:PlayingCardException:Error Msg: Not enough cards to deal

************************************************

Loop # 1

Before shuffle:108 cards

   [Joker #1, Joker #1, A Clubs, 2 Clubs, 3 Clubs, 4 Clubs, 5 Clubs, 6 Clubs, 7 Clubs, 8 Clubs, 9 Clubs, 10 Clubs, J Clubs, Q Clubs, K Clubs, A Diamonds, 2 Diamonds, 3 Diamonds, 4 Diamonds, 5 Diamonds, 6 Diamonds, 7 Diamonds, 8 Diamonds, 9 Diamonds, 10 Diamonds, J Diamonds, Q Diamonds, K Diamonds, A Hearts, 2 Hearts, 3 Hearts, 4 Hearts, 5 Hearts, 6 Hearts, 7 Hearts, 8 Hearts, 9 Hearts, 10 Hearts, J Hearts, Q Hearts, K Hearts, A Spades, 2 Spades, 3 Spades, 4 Spades, 5 Spades, 6 Spades, 7 Spades, 8 Spades, 9 Spades, 10 Spades, J Spades, Q Spades, K Spades, Joker #1, Joker #1, A Clubs, 2 Clubs, 3 Clubs, 4 Clubs, 5 Clubs, 6 Clubs, 7 Clubs, 8 Clubs, 9 Clubs, 10 Clubs, J Clubs, Q Clubs, K Clubs, A Diamonds, 2 Diamonds, 3 Diamonds, 4 Diamonds, 5 Diamonds, 6 Diamonds, 7 Diamonds, 8 Diamonds, 9 Diamonds, 10 Diamonds, J Diamonds, Q Diamonds, K Diamonds, A Hearts, 2 Hearts, 3 Hearts, 4 Hearts, 5 Hearts, 6 Hearts, 7 Hearts, 8 Hearts, 9 Hearts, 10 Hearts, J Hearts, Q Hearts, K Hearts, A Spades, 2 Spades, 3 Spades, 4 Spades, 5 Spades, 6 Spades, 7 Spades, 8 Spades, 9 Spades, 10 Spades, J Spades, Q Spades, K Spades]

==============================================

After shuffle:108 cards

   [5 Hearts, 9 Spades, 10 Hearts, 4 Clubs, K Spades, 4 Spades, 6 Hearts, 9 Spades, Joker #1, K Clubs, 5 Spades, 4 Hearts, K Clubs, K Spades, Q Diamonds, Joker #1, Q Diamonds, 8 Clubs, 3 Spades, 3 Diamonds, 10 Hearts, J Clubs, 2 Clubs, 2 Diamonds, 9 Diamonds, 6 Diamonds, A Hearts, 10 Clubs, K Diamonds, A Diamonds, Q Clubs, A Hearts, 7 Clubs, 8 Hearts, 2 Diamonds, J Diamonds, 4 Spades, 2 Spades, A Spades, 3 Clubs, 8 Spades, Q Clubs, 9 Clubs, J Diamonds, J Hearts, 9 Diamonds, A Diamonds, 5 Clubs, Q Spades, 6 Diamonds, 10 Diamonds, 5 Clubs, 7 Clubs, 5 Diamonds, 3 Clubs, 9 Hearts, 8 Diamonds, 8 Hearts, 8 Diamonds, 5 Spades, Joker #1, 2 Hearts, 4 Diamonds, 6 Hearts, K Hearts, A Clubs, 3 Spades, Q Spades, 10 Spades, J Hearts, 5 Diamonds, J Clubs, 3 Diamonds, 7 Spades, 4 Diamonds, J Spades, 10 Diamonds, 8 Spades, 9 Clubs, K Hearts, 6 Spades, 3 Hearts, 2 Clubs, 9 Hearts, 3 Hearts, J Spades, 6 Clubs, 7 Diamonds, 7 Hearts, 4 Hearts, 7 Diamonds, Q Hearts, K Diamonds, 10 Spades, A Spades, 8 Clubs, 2 Spades, Q Hearts, 2 Hearts, 10 Clubs, A Clubs, 6 Spades, 6 Clubs, 7 Spades, 4 Clubs, Joker #1, 7 Hearts, 5 Hearts]


Hand 0:27 cards

   [3 Hearts, 2 Clubs, 9 Hearts, 3 Hearts, J Spades, 6 Clubs, 7 Diamonds, 7 Hearts, 4 Hearts, 7 Diamonds, Q Hearts, K Diamonds, 10 Spades, A Spades, 8 Clubs, 2 Spades, Q Hearts, 2 Hearts, 10 Clubs, A Clubs, 6 Spades, 6 Clubs, 7 Spades, 4 Clubs, Joker #1, 7 Hearts, 5 Hearts]


Remain:81 cards

   [5 Hearts, 9 Spades, 10 Hearts, 4 Clubs, K Spades, 4 Spades, 6 Hearts, 9 Spades, Joker #1, K Clubs, 5 Spades, 4 Hearts, K Clubs, K Spades, Q Diamonds, Joker #1, Q Diamonds, 8 Clubs, 3 Spades, 3 Diamonds, 10 Hearts, J Clubs, 2 Clubs, 2 Diamonds, 9 Diamonds, 6 Diamonds, A Hearts, 10 Clubs, K Diamonds, A Diamonds, Q Clubs, A Hearts, 7 Clubs, 8 Hearts, 2 Diamonds, J Diamonds, 4 Spades, 2 Spades, A Spades, 3 Clubs, 8 Spades, Q Clubs, 9 Clubs, J Diamonds, J Hearts, 9 Diamonds, A Diamonds, 5 Clubs, Q Spades, 6 Diamonds, 10 Diamonds, 5 Clubs, 7 Clubs, 5 Diamonds, 3 Clubs, 9 Hearts, 8 Diamonds, 8 Hearts, 8 Diamonds, 5 Spades, Joker #1, 2 Hearts, 4 Diamonds, 6 Hearts, K Hearts, A Clubs, 3 Spades, Q Spades, 10 Spades, J Hearts, 5 Diamonds, J Clubs, 3 Diamonds, 7 Spades, 4 Diamonds, J Spades, 10 Diamonds, 8 Spades, 9 Clubs, K Hearts, 6 Spades]

==============================================

After shuffle:81 cards

   [Q Clubs, 6 Diamonds, 4 Hearts, Joker #1, 9 Hearts, 5 Spades, Q Spades, 3 Clubs, 4 Clubs, 4 Spades, 6 Hearts, 10 Hearts, 8 Clubs, 7 Clubs, J Diamonds, A Hearts, 8 Hearts, 3 Spades, Q Diamonds, J Spades, 9 Diamonds, 3 Clubs, 4 Spades, 9 Spades, 2 Diamonds, A Diamonds, Q Diamonds, 10 Spades, Joker #1, K Hearts, A Spades, J Hearts, 5 Hearts, 6 Diamonds, 8 Diamonds, 10 Diamonds, 3 Diamonds, 10 Hearts, K Spades, 8 Diamonds, Q Clubs, 9 Clubs, 10 Diamonds, Joker #1, 5 Spades, 7 Clubs, J Clubs, 2 Clubs, 2 Hearts, J Clubs, 6 Hearts, 9 Diamonds, 9 Clubs, 5 Clubs, J Diamonds, Q Spades, K Spades, 5 Clubs, 2 Spades, 8 Hearts, J Hearts, A Diamonds, A Clubs, 6 Spades, 5 Diamonds, 3 Diamonds, 9 Spades, 8 Spades, 5 Diamonds, 4 Diamonds, 8 Spades, K Hearts, K Diamonds, 3 Spades, 4 Diamonds, 2 Diamonds, 10 Clubs, 7 Spades, K Clubs, A Hearts, K Clubs]


Hand 1:27 cards

   [J Diamonds, Q Spades, K Spades, 5 Clubs, 2 Spades, 8 Hearts, J Hearts, A Diamonds, A Clubs, 6 Spades, 5 Diamonds, 3 Diamonds, 9 Spades, 8 Spades, 5 Diamonds, 4 Diamonds, 8 Spades, K Hearts, K Diamonds, 3 Spades, 4 Diamonds, 2 Diamonds, 10 Clubs, 7 Spades, K Clubs, A Hearts, K Clubs]


Remain:54 cards

   [Q Clubs, 6 Diamonds, 4 Hearts, Joker #1, 9 Hearts, 5 Spades, Q Spades, 3 Clubs, 4 Clubs, 4 Spades, 6 Hearts, 10 Hearts, 8 Clubs, 7 Clubs, J Diamonds, A Hearts, 8 Hearts, 3 Spades, Q Diamonds, J Spades, 9 Diamonds, 3 Clubs, 4 Spades, 9 Spades, 2 Diamonds, A Diamonds, Q Diamonds, 10 Spades, Joker #1, K Hearts, A Spades, J Hearts, 5 Hearts, 6 Diamonds, 8 Diamonds, 10 Diamonds, 3 Diamonds, 10 Hearts, K Spades, 8 Diamonds, Q Clubs, 9 Clubs, 10 Diamonds, Joker #1, 5 Spades, 7 Clubs, J Clubs, 2 Clubs, 2 Hearts, J Clubs, 6 Hearts, 9 Diamonds, 9 Clubs, 5 Clubs]

==============================================

After shuffle:54 cards

   [Q Diamonds, 8 Clubs, Q Diamonds, 8 Diamonds, 5 Hearts, 3 Spades, 3 Clubs, 8 Hearts, Joker #1, 2 Hearts, J Clubs, 6 Hearts, 5 Spades, 4 Hearts, J Diamonds, K Spades, 9 Diamonds, 2 Diamonds, 6 Diamonds, A Spades, 9 Clubs, 6 Hearts, 3 Clubs, 10 Diamonds, 9 Spades, J Hearts, Q Spades, 10 Diamonds, 10 Hearts, 4 Clubs, A Diamonds, 8 Diamonds, 4 Spades, 3 Diamonds, 9 Hearts, 9 Diamonds, K Hearts, 9 Clubs, Joker #1, 7 Clubs, Joker #1, 5 Spades, J Clubs, 2 Clubs, 7 Clubs, Q Clubs, 10 Hearts, 6 Diamonds, Q Clubs, J Spades, 5 Clubs, A Hearts, 10 Spades, 4 Spades]


Hand 2:27 cards

   [10 Diamonds, 10 Hearts, 4 Clubs, A Diamonds, 8 Diamonds, 4 Spades, 3 Diamonds, 9 Hearts, 9 Diamonds, K Hearts, 9 Clubs, Joker #1, 7 Clubs, Joker #1, 5 Spades, J Clubs, 2 Clubs, 7 Clubs, Q Clubs, 10 Hearts, 6 Diamonds, Q Clubs, J Spades, 5 Clubs, A Hearts, 10 Spades, 4 Spades]


Remain:27 cards

   [Q Diamonds, 8 Clubs, Q Diamonds, 8 Diamonds, 5 Hearts, 3 Spades, 3 Clubs, 8 Hearts, Joker #1, 2 Hearts, J Clubs, 6 Hearts, 5 Spades, 4 Hearts, J Diamonds, K Spades, 9 Diamonds, 2 Diamonds, 6 Diamonds, A Spades, 9 Clubs, 6 Hearts, 3 Clubs, 10 Diamonds, 9 Spades, J Hearts, Q Spades]

==============================================

After shuffle:27 cards

   [9 Clubs, J Hearts, 5 Spades, 3 Clubs, 9 Diamonds, J Diamonds, J Clubs, Q Diamonds, 6 Diamonds, Joker #1, Q Spades, 6 Hearts, 8 Diamonds, 10 Diamonds, 2 Hearts, 4 Hearts, 9 Spades, 5 Hearts, 8 Clubs, 2 Diamonds, 3 Clubs, A Spades, 8 Hearts, K Spades, 6 Hearts, 3 Spades, Q Diamonds]


Hand 3:27 cards

   [9 Clubs, J Hearts, 5 Spades, 3 Clubs, 9 Diamonds, J Diamonds, J Clubs, Q Diamonds, 6 Diamonds, Joker #1, Q Spades, 6 Hearts, 8 Diamonds, 10 Diamonds, 2 Hearts, 4 Hearts, 9 Spades, 5 Hearts, 8 Clubs, 2 Diamonds, 3 Clubs, A Spades, 8 Hearts, K Spades, 6 Hearts, 3 Spades, Q Diamonds]


Remain:0 cards

   []

==============================================

After shuffle:0 cards

   []


Hand 4:27 cards
*** In catch block:PlayingCardException:Error Msg: Not enough cards to deal

- Sample output : java PJ4.VideoPoker

[A Hearts, 10 Hearts, Q Hearts, J Hearts, K Hearts]
Royal Flush!
-----------------------------------
[9 Hearts, 10 Hearts, Q Hearts, J Hearts, K Hearts]
Straight Flush!
-----------------------------------
[9 Hearts, 10 Hearts, Q Hearts, J Hearts, 8 Clubs]
Straight!
-----------------------------------
[9 Hearts, 10 Hearts, Q Hearts, J Hearts, 5 Hearts]
Flush!
-----------------------------------
[8 Spades, 8 Clubs, Q Spades, 8 Diamonds, 8 Hearts]
Four of a Kind!
-----------------------------------
[8 Spades, 8 Clubs, Q Spades, 8 Diamonds, J Spades]
Three of a Kind!
-----------------------------------
[8 Spades, 8 Clubs, J Diamonds, 8 Diamonds, J Spades]
Full House!
-----------------------------------
[8 Spades, 9 Diamonds, J Diamonds, 8 Diamonds, J Spades]
Two Pairs!
-----------------------------------
[3 Diamonds, 9 Diamonds, J Diamonds, 8 Diamonds, J Spades]
One Pair!
-----------------------------------
[3 Diamonds, 9 Diamonds, 3 Spades, 8 Diamonds, J Spades]
One Pair!
-----------------------------------
[3 Diamonds, 9 Diamonds, 6 Spades, 8 Diamonds, J Spades]
Sorry, you lost!
-----------------------------------

******************************************************************************************

$ java TestVideoPoker 1000


=> java TestVideoPoker 1000


Payout Table Multiplier
=======================================
Royal Flush | 1000
Straight Flush | 50
Four of a Kind | 25
Full House | 10
Flush | 6
Straight | 5
Three of a Kind | 3
Two Pairs | 2
One Pair | 1

-----------------------------------
Balance:$1000
Enter bet:200
Hand:[3 Diamonds, 9 Diamonds, K Clubs, 8 Hearts, J Clubs]
Enter positions of cards to replace (e.g. 1 4 5 ): <---- keep all cards
Hand:[3 Diamonds, 9 Diamonds, K Clubs, 8 Hearts, J Clubs]
Sorry, you lost!

Your balance:$800, one more game (y or n)?y

Want to see payout table (y or n)y

Payout Table Multiplier
=======================================
Royal Flush | 1000
Straight Flush | 50
Four of a Kind | 25
Full House | 10
Flush | 6
Straight | 5
Three of a Kind | 3
Two Pairs | 2
One Pair | 1

-----------------------------------
Balance:$800
Enter bet:200
Hand:[A Clubs, 2 Clubs, 2 Spades, 4 Hearts, 4 Diamonds]
Enter positions of cards to replace (e.g. 1 4 5 ):1 4 5 <--- keep 2 3
Hand:[K Clubs, 2 Clubs, 2 Spades, Q Clubs, K Spades]
Two Pairs!

Your balance:$1000, one more game (y or n)?y

Want to see payout table (y or n)n
-----------------------------------
Balance:$1000
Enter bet:500
Hand:[6 Clubs, 2 Spades, 5 Spades, J Hearts, 2 Hearts]
Enter positions of cards to replace (e.g. 1 4 5 ):1 2 3 4 5 <---- replace all cards
Hand:[4 Hearts, 2 Diamonds, 10 Clubs, 7 Hearts, 3 Spades]
Sorry, you lost!

Your balance:$500, one more game (y or n)?n

Bye!

PlayingCard class

package PJ4;

import java.util.*;


//=================================================================================
/** class PlayingCardException: It is used for errors related to Card and Deck objects
* Do not modify this class!
*/
class PlayingCardException extends Exception {

/* Constructor to create a PlayingCardException object */
PlayingCardException (){
       super ();
}

PlayingCardException ( String reason ){
       super ( reason );
}
}

//=================================================================================
/** class Card : for creating playing card objects
* it is an immutable class.
* Rank - valid values are 1 to 13
* Suit - valid values are 0 to 4
* Do not modify this class!
*/
class Card {
  
/* constant suits and ranks */
static final String[] Suit = {"Joker","Clubs", "Diamonds", "Hearts", "Spades" };
static final String[] Rank = {"","A","2","3","4","5","6","7","8","9","10","J","Q","K"};

/* Data field of a card: rank and suit */
private int cardRank; /* values: 1-13 (see Rank[] above) */
private int cardSuit; /* values: 0-4 (see Suit[] above) */

/* Constructor to create a card */
/* throw PlayingCardException if rank or suit is invalid */
public Card(int suit, int rank) throws PlayingCardException {

// suit =0 is joker, rank must be 1 or 2
   if (suit==0) {
   if ((rank <1) || (rank >2))
   throw new PlayingCardException("Invalid rank for Joker:"+rank);
   cardRank=rank;
   cardSuit=0;
} else {

   if ((rank < 1) || (rank > 13))
       throw new PlayingCardException("Invalid rank:"+rank);
   else
   cardRank = rank;

   if ((suit < 1) || (suit > 4))
       throw new PlayingCardException("Invalid suit:"+suit);
   else
   cardSuit = suit;
    }
}

/* Accessor and toString */
/* You may impelemnt equals(), but it will not be used */
public int getRank() { return cardRank; }
public int getSuit() { return cardSuit; }
public String toString() {
   if (cardSuit == 0) return Suit[cardSuit]+" #"+cardRank;
else return Rank[cardRank] + " " + Suit[cardSuit];
}

  
/* Few quick tests here */
public static void main(String args[])
{
   try {
   Card c1 = new Card(4,1); // A Spades
   System.out.println(c1);
   c1 = new Card(1,10);   // 10 Clubs
   System.out.println(c1);
   c1 = new Card(0,2);       // Joker #2
   System.out.println(c1);
   c1 = new Card(5,10); // generate exception here
   }
   catch (PlayingCardException e)
   {
   System.out.println("PlayingCardException: "+e.getMessage());
   }
}
}

//=================================================================================
/** class Decks represents : n decks of 52 (or 54) playing cards
* Use class Card to construct n * 52 (or 54) playing cards!
*
* Do not add new data fields!
* Do not modify any methods
* You may add private methods
*/

class Decks {

/* this is used to keep track of original n*52 or n*54 cards */
private List<Card> originalDecks;   

/* this starts with copying cards from originalDecks */
/* it is used to play the card game */
/* see reset(): resets gameDecks to originalDecks */
private List<Card> gameDecks;

/* number of decks in this object */
private int numberDecks;
private boolean withJokers;


/**
* Constructor: Creates one deck of 52 or 54 (withJokers = false or true)
* playing cards in originalDecks and copy them to gameDecks.
* initialize numberDecks=1
* Note: You need to catch PlayingCardException from Card constructor
*   Use ArrayList for both originalDecks & gameDecks
*/
public Decks(boolean withJokers)
{
   originalDecks = new ArrayList<Card>();
numberDecks=1;
for (int i = 0; i < numberDecks; i++) {
  
for (int j = 0; j <= 3; j++) {
for (int k = 1; k <= 13; k++) {
try {
originalDecks.add(new Card(k, j));
} catch (PlayingCardException e) {
System.out.println("PlayingCardException e.getMessage()");
}
}
}
}
gameDecks = new ArrayList<Card>(originalDecks);
}
  
  


/**
* Constructor: Creates n decks (54 or 52 cards each deck - with or without Jokers)
* of playing cards in originalDecks and copy them to gameDecks.
* initialize numberDecks=n
* Note: You need to catch PlayingCardException from Card constructor
*   Use ArrayList for both originalDecks & gameDecks
*/
public Decks(int n, boolean withJokers)
{
originalDecks = new ArrayList<Card>();
numberDecks = n;
for (int i = 0; i < numberDecks; i++) {
  
for (int j = 0; j <= 3; j++) {
for (int k = 1; k <= 13; k++) {
try {
originalDecks.add(new Card(k, j));
} catch (PlayingCardException e) {
System.out.println("PlayingCardException e.getMessage())");
}
}
}
}
ArrayList<Card> dealDecks = new ArrayList<Card>(originalDecks);

  
}
  

/**
* Task: Shuffles cards in deal deck. Hint: Look at java.util.Collections
*/

  


/**
* Task: Shuffles cards in gameDecks.
* Hint: Look at java.util.Collections
*/
public void shuffle()
{
   Collections.shuffle(this.gameDecks);
}

/**
* Task: Deals cards from the gameDecks.
*
* @param numberCards number of cards to deal
* @return a list containing cards that were dealt
* @throw PlayingCardException if numberCard > number of remaining cards
*
* Note: You need to create ArrayList to stored dealt cards
* and should removed dealt cards from gameDecks
*
*/
public List<Card> deal(int numberCards) throws PlayingCardException
{
   // implement this method!
//do random selection of total numberCards from the dealDeck.
List<Card> hand= new ArrayList<Card>();
int selectedIndex=0;
if(numberCards> gameDecks.size()){
throw new PlayingCardException("Not enough cards to deal");
}
else{
selectedIndex = gameDecks.size()-1;
for(int i=0; i<numberCards; i++){
  
hand.add(gameDecks.remove(selectedIndex));
selectedIndex--;
}
}
return hand;
}

/**
* Task: Resets gameDecks by getting all cards from the originalDecks.
*/
public void reset()
{

  
   Card[] holdcards = new Card[52];
holdcards = originalDecks.toArray(holdcards);
copyDeck(0, holdcards);  

}

/**
* Task: Return number of decks.
*/
public int getNumberDecks()
{
   return numberDecks;
}

/**
* Task: Return withJokers.
*/
public boolean getWithJokers()
{
   return withJokers;
}

/**
* Task: Return number of remaining cards in gameDecks.
*/
public int remainSize()
{
   return gameDecks.size();
}

/**
* Task: Returns a string representing cards in the gameDecks
*/
public String toString()
{
   return ""+gameDecks;
}


/* Quick test */
/* */
/* Do not modify these tests */
/* Generate 2 decks of 54 cards */
/* Loop 2 times: */
/* Deal 27 cards for 5 times */
/* Expect exception at 5th time*/
/* reset() */

public static void main(String args[]) {

System.out.println("******* Create 2 decks of cards ******** ");
Decks decks = new Decks(2, true);
System.out.println("getNumberDecks:" + decks.getNumberDecks());
System.out.println("getWithJokers:" + decks.getWithJokers());

   for (int j=0; j < 2; j++)
   {
   System.out.println(" ************************************************ ");
   System.out.println("Loop # " + j + " ");
       System.out.println("Before shuffle:"+decks.remainSize()+" cards");
       System.out.println(" "+decks);
   System.out.println(" ============================================== ");

int numHands = 5;
int cardsPerHand = 27;

   for (int i=0; i < numHands; i++)
      {
           decks.shuffle();
       System.out.println("After shuffle:"+decks.remainSize()+" cards");
       System.out.println(" "+decks);
           try {
       System.out.println(" Hand "+i+":"+cardsPerHand+" cards");
       System.out.println(" "+decks.deal(cardsPerHand));
       System.out.println(" Remain:"+decks.remainSize()+" cards");
       System.out.println(" "+decks);
   System.out.println(" ============================================== ");
           }
           catch (PlayingCardException e)
           {
          System.out.println("*** In catch block:PlayingCardException:Error Msg: "+e.getMessage());
           }
       }


       decks.reset();
   }
}

}

package PJ4;
import java.util.*;

/*
* Ref: http://en.wikipedia.org/wiki/Video_poker
* http://www.freeslots.com/poker.htm
*
*
* Short Description and Poker rules:
*
* Video poker is also known as draw poker.
* The dealer uses a 52-card deck, which is played fresh after each playerHand.
* The player is dealt one five-card poker playerHand.
* After the first draw, which is automatic, you may hold any of the cards and draw
* again to replace the cards that you haven't chosen to hold.
* Your cards are compared to a table of winning combinations.
* The object is to get the best possible combination so that you earn the highest
* payout on the bet you placed.
*
* Winning Combinations
*
* 1. One Pair: one pair of the same card
* 2. Two Pair: two sets of pairs of the same card denomination.
* 3. Three of a Kind: three cards of the same denomination.
* 4. Straight: five consecutive denomination cards of different suit.
* 5. Flush: five non-consecutive denomination cards of the same suit.
* 6. Full House: a set of three cards of the same denomination plus
*    a set of two cards of the same denomination.
* 7. Four of a kind: four cards of the same denomination.
* 8. Straight Flush: five consecutive denomination cards of the same suit.
* 9. Royal Flush: five consecutive denomination cards of the same suit,
*    starting from 10 and ending with an ace
*
*/


/* This is the video poker game class.
* It uses Decks and Card objects to implement video poker game.
* Please do not modify any data fields or defined methods
* You may add new data fields and methods
* Note: You must implement defined methods
*/

public class VideoPoker {

// default constant values
private static final int startingBalance=100;
private static final int numberOfCards=5;

// default constant payout value and playerHand types
private static final int[] multipliers={1,2,3,5,6,10,25,50,1000};
private static final String[] goodHandTypes={
   "One Pair" , "Two Pairs" , "Three of a Kind", "Straight", "Flush   ",
   "Full House", "Four of a Kind", "Straight Flush", "Royal Flush" };

// must use only one deck
private final Decks oneDeck;

// holding current poker 5-card hand, balance, bet
private List<Card> playerHand;
private int playerBalance;
private int playerBet;

/** default constructor, set balance = startingBalance */
public VideoPoker()
{
   this(startingBalance);
}

/** constructor, set given balance */
public VideoPoker(int balance)
{
   this.playerBalance= balance;
Decks(1, false);
}

/** This display the payout table based on multipliers and goodHandTypes arrays */
private void showPayoutTable()
{
   System.out.println(" ");
   System.out.println("Payout Table    Multiplier ");
   System.out.println("=======================================");
   int size = multipliers.length;
   for (int i=size-1; i >= 0; i--) {
       System.out.println(goodHandTypes[i]+" | "+multipliers[i]);
   }
   System.out.println(" ");
}

/** Check current playerHand using multipliers and goodHandTypes arrays
* Must print yourHandType (default is "Sorry, you lost") at the end of function.
* This can be checked by testCheckHands() and main() method.
*/
private void checkHands()
{
// implement this method!
}

/*************************************************
* add new private methods here ....
*
*************************************************/


public void play()
{
/** The main algorithm for single player poker game
*
* Steps:
*        showPayoutTable()
*
*        ++  
*        show balance, get bet
*       verify bet value, update balance
*       reset deck, shuffle deck,
*       deal cards and display cards
*       ask for positions of cards to replace
* get positions in one input line
*       update cards
*       check hands, display proper messages
*       update balance if there is a payout
*       if balance = O:
*           end of program
*       else
*           ask if the player wants to play a new game
*           if the answer is "no" : end of program
*           else : showPayoutTable() if user wants to see it
*           goto ++
*/

// implement this method!

}

/*************************************************
* Do not modify methods below
/*************************************************

/** testCheckHands() is used to test checkHands() method
* checkHands() should print your current hand type
*/

public void testCheckHands()
{
   try {
       playerHand = new ArrayList<Card>();

       // set Royal Flush
       playerHand.add(new Card(3,1));
       playerHand.add(new Card(3,10));
       playerHand.add(new Card(3,12));
       playerHand.add(new Card(3,11));
       playerHand.add(new Card(3,13));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Straight Flush
       playerHand.set(0,new Card(3,9));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Straight
       playerHand.set(4, new Card(1,8));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Flush
       playerHand.set(4, new Card(3,5));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // "Royal Pair" , "Two Pairs" , "Three of a Kind", "Straight", "Flush   ",
      // "Full House", "Four of a Kind", "Straight Flush", "Royal Flush" };

       // set Four of a Kind
       playerHand.clear();
       playerHand.add(new Card(4,8));
       playerHand.add(new Card(1,8));
       playerHand.add(new Card(4,12));
       playerHand.add(new Card(2,8));
       playerHand.add(new Card(3,8));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Three of a Kind
       playerHand.set(4, new Card(4,11));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Full House
       playerHand.set(2, new Card(2,11));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set Two Pairs
       playerHand.set(1, new Card(2,9));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set One Pair
       playerHand.set(0, new Card(2,3));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set One Pair
       playerHand.set(2, new Card(4,3));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");

       // set no Pair
       playerHand.set(2, new Card(4,6));
       System.out.println(playerHand);
       checkHands();
       System.out.println("-----------------------------------");
   }
   catch (Exception e)
   {
       System.out.println(e.getMessage());
   }
}

/* Quick testCheckHands() */
public static void main(String args[])
{
   VideoPoker pokergame = new VideoPoker();
   pokergame.testCheckHands();
}
}

estVideoPoker class, to test the program and on separate pakage.

/*************************************************************************************
*
* This program is used to test PJ4.VideoPoker class
* More info are given in Readme file
*
* PJ4 class allows user to run program as follows:
*
*     java PJ4       // default credit is $100
* or    java PJ4 NNN       // set initial credit to NNN
*
* Do not modify this file!
*
**************************************************************************************/

import PJ4.VideoPoker;

class TestVideoPoker {

public static void main(String args[])
{
   VideoPoker pokergame;
   if (args.length > 0)
       pokergame = new VideoPoker(Integer.parseInt(args[0]));
   else
       pokergame = new VideoPoker();
   pokergame.play();
}
}

Output

Explanation / Answer

Hi ,

Please find the code below for class deck.

public class Card {

  

   public final static int SPADES = 0;   // Codes for the 4 suits, plus Joker.

   public final static int HEARTS = 1;

   public final static int DIAMONDS = 2;

   public final static int CLUBS = 3;

   public final static int JOKER = 4;

  

   public final static int ACE = 1;      // Codes for the non-numeric cards.

   public final static int JACK = 11;    //   Cards 2 through 10 have their

   public final static int QUEEN = 12;   //   numerical values for their codes.

   public final static int KING = 13;

  

   /**

    * This card's suit, one of the constants SPADES, HEARTS, DIAMONDS,

    * CLUBS, or JOKER. The suit cannot be changed after the card is

    * constructed.

    */

   private final int suit;

  

   /**

    * The card's value. For a normal card, this is one of the values

    * 1 through 13, with 1 representing ACE. For a JOKER, the value

    * can be anything. The value cannot be changed after the card

    * is constructed.

    */

   private final int value;

  

   /**

    * Creates a Joker, with 1 as the associated value. (Note that

    * "new Card()" is equivalent to "new Card(1,Card.JOKER)".)

    */

   public Card() {

      suit = JOKER;

      value = 1;

   }

  

   /**

    * Creates a card with a specified suit and value.

    * @param theValue the value of the new card. For a regular card (non-joker),

    * the value must be in the range 1 through 13, with 1 representing an Ace.

    * You can use the constants Card.ACE, Card.JACK, Card.QUEEN, and Card.KING.

    * For a Joker, the value can be anything.

    * @param theSuit the suit of the new card. This must be one of the values

    * Card.SPADES, Card.HEARTS, Card.DIAMONDS, Card.CLUBS, or Card.JOKER.

    * @throws IllegalArgumentException if the parameter values are not in the

    * permissible ranges

    */

   public Card(int theValue, int theSuit) {

      if (theSuit != SPADES && theSuit != HEARTS && theSuit != DIAMONDS &&

            theSuit != CLUBS && theSuit != JOKER)

         throw new IllegalArgumentException("Illegal playing card suit");

      if (theSuit != JOKER && (theValue < 1 || theValue > 13))

         throw new IllegalArgumentException("Illegal playing card value");

      value = theValue;

      suit = theSuit;

   }

   /**

    * Returns the suit of this card.

    * @returns the suit, which is one of the constants Card.SPADES,

    * Card.HEARTS, Card.DIAMONDS, Card.CLUBS, or Card.JOKER

    */

   public int getSuit() {

      return suit;

   }

  

   /**

   * Returns the value of this card.

    * @return the value, which is one of the numbers 1 through 13, inclusive for

    * a regular card, and which can be any value for a Joker.

    */

   public int getValue() {

      return value;

   }

  

   /**

    * Returns a String representation of the card's suit.

    * @return one of the strings "Spades", "Hearts", "Diamonds", "Clubs"

    * or "Joker".

    */

   public String getSuitAsString() {

      switch ( suit ) {

      case SPADES:   return "Spades";

      case HEARTS:   return "Hearts";

      case DIAMONDS: return "Diamonds";

      case CLUBS:    return "Clubs";

      default:       return "Joker";

      }

   }

  

   /**

    * Returns a String representation of the card's value.

    * @return for a regular card, one of the strings "Ace", "2",

    * "3", ..., "10", "Jack", "Queen", or "King". For a Joker, the

    * string is always numerical.

    */

   public String getValueAsString() {

      if (suit == JOKER)

         return "" + value;

      else {

         switch ( value ) {

         case 1:   return "Ace";

         case 2:   return "2";

         case 3:   return "3";

         case 4:   return "4";

         case 5:   return "5";

         case 6:   return "6";

         case 7:   return "7";

         case 8:   return "8";

         case 9:   return "9";

         case 10: return "10";

         case 11: return "Jack";

         case 12: return "Queen";

         default: return "King";

         }

      }

   }

  

   /**

    * Returns a string representation of this card, including both

    * its suit and its value (except that for a Joker with value 1,

    * the return value is just "Joker"). Sample return values

    * are: "Queen of Hearts", "10 of Diamonds", "Ace of Spades",

    * "Joker", "Joker #2"

    */

   public String toString() {

      if (suit == JOKER) {

         if (value == 1)

            return "Joker";

         else

            return "Joker #" + value;

      }

      else

         return getValueAsString() + " of " + getSuitAsString();

   }

  

} // end class Card

**********************************************************************************************************

public class Play {

   public static void main(String[] args) {

  

      System.out.println("This program lets you play the simple card game,");

      System.out.println("Play. A card is dealt from a deck of cards.");

      System.out.println("You have to predict whether the next card will be");

      System.out.println("higher or lower. Your score in the game is the");

      System.out.println("number of correct predictions you make before");

      System.out.println("you guess wrong.");

      System.out.println();

     

      int gamesPlayed = 0;     // Number of games user has played.

      int sumOfScores = 0;     // The sum of all the scores from

                               //      all the games played.

      double averageScore;     // Average score, computed by dividing

                               //      sumOfScores by gamesPlayed.

      boolean playAgain;       // Record user's response when user is

                               //   asked whether he wants to play

                               //   another game.

     

      do {

         int scoreThisGame;        // Score for one game.

         scoreThisGame = play();   // Play the game and get the score.

         sumOfScores += scoreThisGame;

         gamesPlayed++;

         System.out.print("Play again? ");

         playAgain = TextIO.getlnBoolean();

      } while (playAgain);

     

      averageScore = ((double)sumOfScores) / gamesPlayed;

     

      System.out.println();

      System.out.println("You played " + gamesPlayed + " games.");

      System.out.printf("Your average score was %1.3f. ", averageScore);

  

   } // end main()

  

   /**

    * Lets the user play one game of Play, and returns the

    * user's score in that game. The score is the number of

    * correct guesses that the user makes.

    */

   private static int play() {

  

      Deck deck = new Deck(); // Get a new deck of cards, and

                               //   store a reference to it in

                               //   the variable, deck.

     

      Card currentCard; // The current card, which the user sees.

      Card nextCard;   // The next card in the deck. The user tries

                       //    to predict whether this is higher or lower

                       //    than the current card.

      int correctGuesses ; // The number of correct predictions the

                            //   user has made. At the end of the game,

                            //   this will be the user's score.

      char guess;   // The user's guess. 'H' if the user predicts that

                    //   the next card will be higher, 'L' if the user

                    //   predicts that it will be lower.

     

      deck.shuffle(); // Shuffle the deck into a random order before

                       //    starting the game.

      correctGuesses = 0;

      currentCard = deck.dealCard();

      System.out.println("The first card is the " + currentCard);

     

      while (true) { // Loop ends when user's prediction is wrong.

        

         /* Get the user's prediction, 'H' or 'L' (or 'h' or 'l'). */

        

         System.out.print("Will the next card be higher (H) or lower (L)? ");

         do {

            guess = TextIO.getlnChar();

             guess = Character.toUpperCase(guess);

             if (guess != 'H' && guess != 'L')

                System.out.print("Please respond with H or L: ");

         } while (guess != 'H' && guess != 'L');

        

       /* Get the next card and show it to the user. */

        

         nextCard = deck.dealCard();

         System.out.println("The next card is " + nextCard);

        

         /* Check the user's prediction. */

        

         if (nextCard.getValue() == currentCard.getValue()) {

            System.out.println("The value is the same as the previous card.");

            System.out.println("You lose on ties. Sorry!");

            break; // End the game.

         }

         else if (nextCard.getValue() > currentCard.getValue()) {

            if (guess == 'H') {

                System.out.println("Your prediction was correct.");

                correctGuesses++;

            }

            else {

                System.out.println("Your prediction was incorrect.");

                break; // End the game.

            }

         }

         else { // nextCard is lower

            if (guess == 'L') {

                System.out.println("Your prediction was correct.");

                correctGuesses++;

            }

            else {

                System.out.println("Your prediction was incorrect.");

                break; // End the game.

            }

         }

        

         /* To set up for the next iteration of the loop, the nextCard

            becomes the currentCard, since the currentCard has to be

            the card that the user sees, and the nextCard will be

            set to the next card in the deck after the user makes

            his prediction. */

        

         currentCard = nextCard;

         System.out.println();

         System.out.println("The card is " + currentCard);

        

      } // end of while loop

     

      System.out.println();

      System.out.println("The game is over.");

      System.out.println("You made " + correctGuesses

                                           + " correct predictions.");

      System.out.println();

     

      return correctGuesses;

     

   } // end play()

}