Skip to content

Instantly share code, notes, and snippets.

@nhu313
Last active February 22, 2019 14:18
Show Gist options
  • Save nhu313/f92824e008ff0aa48836af86a847153f to your computer and use it in GitHub Desktop.
Save nhu313/f92824e008ff0aa48836af86a847153f to your computer and use it in GitHub Desktop.

Casino

Create the following classes:

Card

Instance variables/Fields

  • String suite
  • String faceValue

Constructors

  • Card(String suite, String faceValue) - set the parameter fields to the instance fields

Methods

  1. Create a getter method called String getSuite to return the suite of the card. The return type is String.
  2. Create a setter method called void setSuite(String newSuite) and set the newSuite parameter to the suite field. There is no return type.
  3. Create a getter method called String getFaceValue to return the face value of the card. The return type is String.
  4. Create a setter method called void setFaceValue(String newFaceValue) and set the newFaceValue parameter to the faceValue field.

Deck

Instance variables/Fields

  • ArrayList<Card> cards

Constructors

  • Deck() - create an empty constructor. In the constructor, set the card field to a new instance of ArrayList. cards = new ArrayList<Card>()

Methods

  1. Create a getter method called ArrayList<Card> getCards to return the cards field. The return type is a ArrayList<Card>.
  2. Create a method called void addCard(Card card) and add the card in the parameter to the field cards list.
  3. Create a method called int size() which returns how many card is in the list.
  4. Create a method called Card draw() which remove the card at index 0 from the list

Player

Instance variables/Fields

  • String name
  • ArrayList<Card> hand

Constructors

  • Player() - create an empty constructor. In the constructor, set the hand field to a new instance of ArrayList. hand = new ArrayList<Card>()

Methods

  1. Create a getter method called ArrayList<Card> getHand to return the hand field. The return type is a ArrayList<Card>.
  2. Create a method called void takeCard(Card card) and add the card in the parameter to the field hand list.
  3. Create a getter method called String getName to return the name of the player. The return type is String.
  4. Create a setter method called void setName(String newName) and set the newName parameter to the name field. There is no return type.

BlackJackGame

Instance variables/Fields

  • Player player1
  • Player player2
  • Deck deck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment