Intro to Java Project 4: Casino Night
Background
Now that we know how to make Objects, we can use them to make programs that would have been very complicated otherwise. In this assignment, you will create a class that represents a single playing card (the Card class), and another class that represents a deck of playing cards (the Deck class). Once you complete both of the classes, you can test your work by running a simple java Blackjack game that will be provided to you.
Exercise
● Your job is to create and submit two new files: Card.java and Deck.java. The classes will need to follow these requirements: ○ The Card class: ■ Private variables: Will have two private String variables: suit and value. Suits are either “hearts”, “diamonds”, “clubs”, “spades”. Values are “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”, “jack”, “queen”, “king”, “ace”. ■ Constructor: The constructor to the Card class will take in a suit String, ■ Public Methods: Your class must have the following methods with the others to edit at the same time. specified return types. ● public String getSuit() // returns the suit of the card (either “hearts”, “diamonds”, “spades”, or “clubs”) ● public String getValue() // returns the value of the card (“ace”, “two”, “three”, ... “jack”, “queen”, “king”) ● public String getColor() // returns the color of the card (“red” or “black”). Hearts and Diamonds are red, Spades & Clubs are black. ● public String toString() // returns a String representation of the Card. Should look something like “ace of clubs” or “six of hearts” ○ The Deck class: ■ Private variables: Will have one private variable called deck: an ArrayList of Card objects representing the deck of cards. ■ Constructor: The constructor to the Deck class takes no arguments. Inside the constructor, you should create 52 card objects representing the 52 cards in a deck, and add them to the private deck variable. Hint: use loops! ■ Public Methods: Your class must have the following methods with the specified return types. ● public void shuffle() // shuffle the deck using a Random object. It should not return anything. ● public Card deal() // remove a Card object from one end of the deck and return it. Don’t worry about checking if the deck is empty.
Testing
To test your code AND play a fun game of Blackjack, put the Hand.java and Blackjack.java files into the same folder as your Card.java and Deck.java files. Then, compile & run Blackjack.java to play the game. I suggest playing the game a few times to make sure everything works properly. After playing for a little bit, submit only Card.java and Deck.java to gradescope to make sure the autograder is happy as well. Here is some sample output from a successful game of blackjack (and yeah, I won):'
VERY IMPORTANT NOTE: Gradescope will compile and run Blackjack.java to test your code. I understand that you did not create Blackjack.java. When Compiling Blackjack.java, java also compiles Card.java, Deck.java, and Hand.java. If the program compiles and says there is an issue within Blackjack.java, it means there’s a problem with the code that call into your classes! Blackjack.java was compiled and tested before going onto Gradescope.