Question: CSCI 1101 - Computer Science II Assignment No. 3 Date Given: Sunday March 4, 2018 Date Due: Friday March 16, 11:00 pm Submission: Brightspace Please
CSCI 1101 - Computer Science II
Assignment No. 3
Date Given: Sunday March 4, 2018
Date Due: Friday March 16, 11:00 pm
Submission: Brightspace
Please follow all the instructions carefully. You must submit one zip file containing the source codes (.java files) and a text document with sample outputs. All your programs must be nicely formatted, commented, and tested or you will loose marks.
This assignment will test your skills in object-oriented programming with multiple classes and the use of ArrayLists as the data structure.
You are to design a simple card game called War (see http://www.bicyclecards.com/how-to-play/war/ for a detailed description of the card game). In this game, there are two players who each get half the deck of cards (26 cards each). Players, at the same time, flip over the top card on their pile. The player who flips the higher value/rank card wins and gets both cards. The winning player adds both cards to their pile of cards. If both players flip over cards with the same value/rank, then a "War" starts. When "War" is declared both players put four cards into a separate pile and flip over the top card. The player who flips over the highest card wins the "War" pile. If the players both turn over the same card while at War, you play War again (etc.). The game then resumes as normal (one card at a time). The game ends when one player runs out of cards. The winner has all the cards. You can play an online version of the game here https://cardgames.io/war/.
You will have three Classes (Card, Deck and a Demo Class).
Card Class
You need to first create a Card Class. A Card object is made up of a suit (which are Hearts, Diamonds, Clubs, and Spades). Each suit has the same set of ranked cards: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. And each card has a value (e.g., you could make Ace=14, King=13, Queen=12, Jack=11, then the numbered values e.g., "2" has a value of 2, "8" has a value of 8. The suit of the card doesn't matter in this game (that is only the rank and value of a card matter but you need to print out the suit in your output).
The order of best to worst cards: Ace, King, Queen, Jack, 10, 9, 8, 7, 6, 5, 4, 3, 2. Nothing beats an Ace and a 2 doesn't beat anything.
Deck Class
You will then create a Class called Deck. This class will store the Cards as an ArrayList (52 cards in total made up of 4 suites of cards) a "deck" of cards. You will also need to have methods related to a deck of cards a way to create and populate the ArrayList with all the different Cards, get and set methods, and in particular a shuffle method. The shuffle method will reorder the cards in the ArrayList into a random order. There are many ways that you can shuffle a deck of cards. You can search for an algorithm for shuffling (make sure you reference any source you sue) or you can use a simple approach of generating two random indices in the deck and swapping the cards several times (e.g., 52).
Demo Class (play the game)
In your Demo class, you will ask two players for their names, create a deck of cards and shuffle them. Then you will "deal" the cards into two hands (give each player their own pile of cards) so that each player has 26 cards (that is each player will have their own ArrayList with their pile of cards). Then play the game. This is an automated game, meaning once you start the game, the cards in each players hand (pile) will automatically keep flipping until a winner is found.
Note, your display must be like the above. You can use the printf function to help you format strings so that the columns line up. See this source to help you format your printf:
https://alvinalexander.com/programming/printf-format-cheat-sheet.
See the below sample output, for an example of how the game plays.
Welcome to WAR! Let's Play!
Enter the first player's name: BOB
Enter the second player's name: SUE
BOB #Cards SUE #Cards Winner
2 Clubs 26 Jack Hearts 26 SUE
9 Clubs 25 Ace Clubs 27 SUE
King Spades 24 Jack Spades 28 BOB
6 Spades 25 6 Diamonds 27 WAR
************************************************WAR*******************************************
4 Spades 25 6 Hearts 27 SUE
************************************************END WAR***************************************
9 Hearts 20 10 Diamonds 32 SUE
5 Clubs 1 Queen Spades 51 SUE
SUE Wins! Congratulations
Play again (y/n)? n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
