QuestionQuestion

Transcribed TextTranscribed Text

Play Card Game Create a Java program that will simulate a card game in which four players will play the game with a deck of cards. Assume the deck of cards represents a typical playing deck of cards containing 52 cards that has a face rank (e.g., “Ace”, “Deuce”, “Three”…………”Ten”, “Jack”, “Queen”, “King”) and a suit (e.g., “Spades”, “Hearts”, “Diamonds”, “Clubs”). Each suit has 13 cards one for each face. Table 1 and Table 2 show a mapping for the suits and card faces, respectively. You should use these integer code values, NOT the string names, in your simulation program to represent a suit and a card face rank. For example, the code for the card ‘Five of Spade’ should be two integer values as 3 5, where the first value indicates the suite rank (i.e., Spade) and the second value indicates the face rank. Similarly, ‘Ace of Clubs’ = 0 14, ‘Jack of Hearts = 2 11, and so on. Table 1: Suit code Suit Clubs Diamonds Hearts Spades Suit code 0 1 2 3 Table 2: Card face rank code Card face Deuce Three Four Five Six Seven Eight Nine Ten Jack Queen King Ace Code 2 3 4 5 6 7 8 9 10 11 12 13 14 Rules to play: Step 1 (Shuffle): Shuffle all cards (52 cards in the deck of cards) to obtain a random order for the cards in the deck. Step 2 (Distribute): Distribute the cards among four players in 13 rounds, starting from the first card in the shuffled deck of cards, i.e., one player will get 1 card in each round from the randomly shuffled deck of card. For example, in the 1st round of distribution, Player-1 will receive the 1st card, Player-2 will receive the 2nd card, Player-3 will receive the 3rd card, and Player-4 will receive the 4th card. In the 2nd round of distribution, Player-1 will receive the 5th card, Player-2 will receive the 6th card, Player-3 will receive the 7th card, and Player-4 will receive the 8th card, and so on. Thus, at the end of the distribution, each player will receive 13 random cards in total. Step 3 (Play): There will be 13 rounds of deal in the play. For each round, each player will deal (i.e., play) one card. Each player will play a card in the order he/she received the cards. For example, for the 1st round of deal, all players will play the cards that they received in the 1st round of distribution. Similarly, in the 2nd round of deal, they will play the cards they received in the 2nd round of distribution, and so on. Page 2 of 5 Step 4 (Find deal winner): The winner of a deal will be selected based on the face ranks of the four cards played by four players. The player who plays the card with the highest rank among all four cards in a deal is the winner of that deal. For example, assume the status of the 1st round deal (Deal number 01) of a typical play is as follows. Deal number 01: 0 3, 2 7, 0 9, 1 4 It displays the cards played by all players in sequence of players’ order (i.e., Player-1 has played card 0 3, which is 3 of Clubs, Player-2 has played card 2 7, Player-3 has played 0 9, and Player-4 has played the card 1 4. The winner of this deal is Player-3 (who played the card with the highest face rank, i.e., 9). If there is a tie on face ranks (among more than one cards), the winner will be selected based on the suit rank of cards (the higher suit value will get higher rank). For example, if the status of a round of deal is as follows: Deal number 01: 0 3, 2 7, 0 7, 1 4 Then, the winner of this deal is Player-2 (Player-2 and Player-3 played the highest ranked cards (i.e., 7) in the deal, but between them, Player-2 played the card from a higher suit (i.e., 2)). Step 5 (Select the Winner): The overall winner of the game is/are the player(s) who win(s) the highest number of deals among all 13 deals. Input of your simulation: Typically, your program should not require any input from user. The inputs are two fixed code tables, which can be hard coded using suitable data structures (e.g., Array or ArrayList) into your code. However, you may want to create an interactive menu to allow user to play multiple times, which is optional. Output of your simulation: You must display the followings: 1. Your name and Id at the beginning of display 2. Cards for each player after Step 2 (Distribution) 3. All deal information after Step 3 (Play) 4. Total number of deal wins for each player and the winner(s) after Step 4 and Step 5 A typical output should be as follows: Card Game simulation by <Your Name (ID)> Distribution of cards: Cards for player 1 0 4 0 9 2 12 1 6 2 10 Page 3 of 5 0 3 2 8 1 8 2 5 1 3 3 3 2 2 3 5 Cards for player 2 1 11 1 12 2 7 0 14 0 13 3 4 3 8 2 14 2 13 1 14 2 4 3 6 3 14 Cards for player 3 3 11 1 5 2 9 2 3 1 2 0 11 0 6 1 7 2 11 3 12 0 5 3 9 0 2 Cards for player 4 0 8 1 4 3 2 Page 4 of 5 0 7 3 13 3 7 3 10 0 10 1 10 2 6 0 12 1 13 1 9 Status of all deals after 13: Deal number 01: 0 4, 1 11, 3 11, 0 8 Deal number 02: 0 9, 1 12, 1 5, 1 4 Deal number 03: 2 12, 2 7, 2 9, 3 2 Deal number 04: 1 6, 0 14, 2 3, 0 7 Deal number 05: 2 10, 0 13, 1 2, 3 13 Deal number 06: 0 3, 3 4, 0 11, 3 7 Deal number 07: 2 8, 3 8, 0 6, 3 10 Deal number 08: 1 8, 2 14, 1 7, 0 10 Deal number 09: 2 5, 2 13, 2 11, 1 10 Deal number 10: 1 3, 1 14, 3 12, 2 6 Deal number 11: 3 3, 2 4, 0 5, 0 12 Deal number 12: 2 2, 3 6, 3 9, 1 13 Deal number 13: 3 5, 3 14, 0 2, 1 9 Deal winners: Player: No. of Deal(s) Won 1: 1 2: 6 3: 2 4: 4 Overall winner(s): Player-2 Some basic requirements: You are required to satisfy at least the following requirements: 1. You must demonstrate the use of ArrayList in your simulation. For example, you may want to use ArrayList to store deal winners for later display. 2. You must create a separate class (e.g., Card) to handle card information. You should create (arrays of) Card objects to simulate cards in your simulation. Page 5 of 5 3. You must implement the card shuffling logic in your simulation. You should not use any built-in shuffle() method from Collections. (We may use the shuffle() Collections method in future.) 4. You must follow Java code writing convention for all variable, method, interface, and class names. 5. Your simulation must show a decent demonstration of modularizing the whole problem through a set of appropriately functioned methods and classes.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.ArrayList;

public class Player {
    private ArrayList<Card> hand;
    private int number;
    private int score;
    public Player(int number) {
       hand = new ArrayList<>();
       this.number = number;
       score = 0;
    }
   
    /**
    *
    * @param index
    * @return a card in hand at index
    */
    public Card get(int index){
       return hand.get(index);
    }
   
    /**
    * increase the score
    */
    public void score(){
       score++;
    }...
$35.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats