CSIS-120 Project 4: A Better Baccarat

Mrs. White, Fall 2010

Due Monday, November 22, before midnight

Procedures

  • Submit your .java files through the Project 4 Assignment manager on BlackBoard. I will generate a JavaDoc from your source code, which will be graded as part of programming style.
  • This homework is an individual assignment. No collaboration on answers is allowed. Failure to heed this instruction will constitute a violation of the academic honesty policy in the syllabus.
  • Your code must follow the basic conventions of programming style noted in lecture and in your lab manual.

What is a Better Baccarat?

This project is based on Project 2, completed earlier this semester. In this version of Baccarat, there will be one banker and a number of players specified by the user. The game will be played using a Shoe, which is a collection of standard 52 card decks shuffled together. When the number of cards in the shoe drops below a certain amount, all cards are shuffled together again and placed back in the shoe. At the end of each round, the user will be prompted to play again. Game play will continue until the master user indicates s/he no longer wants to play.

Follow the directions for each class below to complete this project. You may wish to use your project 2 as a starting point or you may use the project 2 sample code provided.

Grading Scheme:

15%Program style as noted on the lab manual and lecture discussions, including JavaDoc

10%Correctness of the Suit and Card classes as described

10%Correctness of the Deck class as described

10%Correctness of the Shoe class as described

10%Correctness of the Hand class as described

15%Correctness of the Player class as described

15%Correctness of the Baccarat class as described

15%Correctness of the Driver class as described

Suit Class

A standard deck of 52 cards has 4 suits: hearts, diamonds, spades, and clubs. The Suit class will

  1. define a public constant Suit object for each possible Suit
  2. define a field variable, which is the name of the Suit
  3. have a constructor which is used to initialize the name of the Suit
  4. have a toString method which returns the name of the Suit

Card Class

A Card has a Suit (as described above) and a rank (1 = Ace, 11 = Jack, 12 = Queen, 13 = King, 2 – 9 = 2 – 9). The Card class will

  1. have two field variables, one for the Suit and one for the rank
  2. have a constructor that initializes the fields
  3. have accessor methods for each field
  4. have a rankToString method that returns the name of the Card; e.g., Ace, 2, Jack
  5. have a toString method that returns a String which indicates the name of the Card and its Suit; e.g., Ace of Spades, 2 of Diamonds, Jack of Clubs

Deck Class

A Deck of Cards is made up of the Cards Ace, 2 – 9, Jack, Queen, King, for each of the four possible Suits, for a total of 52 cards. The Deck class will

  1. have a field which is an ArrayList of Card objects
  2. the constructor will create the ArrayList and add the cards for each of the four possible Suits to the Deck using the constants defined in the Suit class; it will then call a method to shuffle the Deck
  3. the shuffle method will randomize the order of Cards in the Deck
  4. the reset method will do the same as the constructor; your constructor should call this method
  5. the size method will return the number of Cards in the Deck
  6. the deal method will return the last Card in the ArrayList; if there are no Cards in the Deck, it should return null
  7. a second deal method will return the requested number of Cards in an ArrayList; it should return null if there are not enough Cards in the ArrayList to fulfill the request
  8. a toString method will return a String which lists all Cards in the Deck, one per line, using the toString method of the Card class

Shoe Class

A Shoe is used in card games to minimize card counting. A Shoe contains a certain number of Decks of Cards, shuffled together. When the number of cards left in the Shoe drops below a certain level, the cards are reshuffled. The Shoe class will

  1. have field variables for the Number of Decks in the Shoe, the number of Cards remaining in the Shoe that will trigger a reshuffle, and an ArrayList of Cards which represents the Shoe
  2. the constructor will initialize the field variables; the number of Decks in the Shoe will be specified as a parameter to the constructor; the number of Cards remaining in the Shoe that will trigger a reshuffle will be 5% of the total number of Cards in the Shoe; all of the Cards in the Shoe must be shuffled (not each Deck individually)
  3. the shuffleCards method will shuffle all Cards in the Shoe
  4. the drawCards method will return an ArrayList of Cards which is equal in size to the requested number; the Cards will be reshuffled, if necessary, before drawing the number of requested cards

Hand Class

The Hand class represents a Hand in Baccarat, which can have at most 3 Cards. Cards in a Hand are drawn from the Shoe used in the Baccarat game. The Hand class will

  1. have a field which represents the Shoe used in the game, and an ArrayList of Cards in the Hand
  2. the constructor will take as parameters the Shoe that Cards are to be drawn from and the number of cards to be dealt initially; in Baccarat, 2 cards are dealt when a new Hand is created; the field variables should be initialized appropriately
  3. the getCardPoints method will return the number of points given a Card value; e.g., given an 11, which represents Jack, a 0 is returned; refer to the Rules for Baccarat from Project 2
  4. the hit method should deal a third Card from the Shoe, if the Hand does not already have one
  5. the getTotal method should return the total number of points in the Hand
  6. the getCard method should return the specified Card number; e.g., a 1 would indicate the first Card in the Hand; if the Card does not exist, the method should return null
  7. the toString method should return the Cards in the hand, one per line, using the toString method from the Card class

Player Class

This class represents one person in the game, whether the banker or another Player. This class will

  1. have fields to represent the Player’s name, Hand, and whether the Player is a winner
  2. the constructor initialize the field variables; it will take as parameters the name of the Player, the Shoe to be used when playing, and the number of cards to be dealt initially (2, in the case of Baccarat)
  3. have accessor methods for each field
  4. have a mutator to set the value of the winner field

Baccarat

The Baccarat class will be used to play one round of Baccarat, as in Project 2. It will

  1. have as fields an ArrayList of Players, a Banker (Player), a Shoe, and constant values representing the number of Decks in the Shoe (3) and the number of cards to be dealt initially (2); the Shoe must be a static variable as the same Shoe will be used with all other objects in the project
  2. the constructor will create the Shoe, banker, and players; the number of players will be specified as a parameter
  3. the setupNewRound method will create a new banker and the same number of new Players as previously specified; note that the same Shoe will be used and should not be recreated once created in the constructor
  4. the play method will control the play of the game; for each Player, it will deal the Player’s final card as specified in the rules outlined in Project 2, and will set the Player’s winner field appropriately; Note that the Banker starts with 2 Cards, as does any Player. The Banker will then get a 3rd Card if s/he can under the rules when playing against Player 1. Whether Player 1 wins is then determined. If the Banker does not get a 3rd Card against Player 1, s/he can get a 3rd Card against Player 2 under the rules. Whether Player 2 wins is then determined. Etc., for all Players. Once the Banker is dealt a 3rd Card, s/he can no longer add Cards to his/her Hand.
  5. the toString method will return a String representing the state of the Baccarat object; its format should be as shown below for 3 Players; Notice that nothing is displayed if a Hand does not contain a third Card; columns of output should be maintained for each Player; a win or loss is determined for each Player versus the Banker individually; ties will go to the Banker

Driver Class

The Driver class will contain a static void main method. From within this method,

  1. the user will be greeted and asked the enter the number of Players via the keyboard.
  2. a Baccarat object will be created
  3. the game will be played by calling the play method of the Baccarat object
  4. Output for the game will be sent to the terminal window; this will include the Game number and a call to the Baccarat object’s toString method
  5. The master user will be prompted to indicate whether s/he wants to play again; play will continue until the master user indicates s/he no longer wants to play. You program should be able to handle all input for this prompt.
  6. When the master user is done playing, a message indicating the game has ended will be printed to the terminal window

Other Project Notes

  • You may add additional private methods to your classes if necessary and especially where they demonstrate good class design.
  • You should use the escape sequence \f to clear the terminal window programmatically after the user indicates whether s/he would like to play again.

© Pauline White, Siena CollegePage 1 of 5