SlideShare a Scribd company logo
1 of 15
Download to read offline
Please use java to write the program that simulates the card game!!! Thx!!!
Given codes:
Dealer.java :
import java.util.Random;
/**
* This class represents a dealer who shuffles a deck of cards and
* distributes them to players.
*/
public class Dealer {
private Deck deck;
/**
* Creates a new Dealer object with the specified players and deck.
*
* @param players the array of CardPlayer objects to distribute the cards to
* @param deck the Deck object to shuffle and distribute
*/
public Dealer(CardPlayer[] players, Deck deck) {
this.deck = deck;
this.shuffle();
this.distribute(players, this.deck);
}
/**
* Distributes the cards in the deck to the specified players.
*
* @param players the array of CardPlayer objects to distribute the cards to
* @param deck the Deck object to distribute
*/
private void distribute(CardPlayer[] players, Deck deck) {
for (int cardCounter = 0; cardCounter < deck.cards.length; cardCounter += players.length) {
for (int playerCounter = 0; playerCounter < players.length; playerCounter++) {
players[playerCounter].addToHand(deck.cards[cardCounter + playerCounter]);
}
}
}
/**
* Shuffles the cards in the deck; it generates two random variables as the card
* index and swaps them.
*/
private void shuffle() {
Random randomNumber = new Random();
for (int card = 0; card < this.deck.cards.length; card++) {
swap(randomNumber.nextInt(deck.cards.length), randomNumber.nextInt(deck.cards.length));
}
}
/**
* Swaps the positions of two cards in the deck.
*
* @param random1 the index of the first card to swap
* @param random2 the index of the second card to swap
*/
private void swap(int random1, int random2) {
Card temp;
temp = this.deck.cards[random1];
this.deck.cards[random1] = this.deck.cards[random2];
this.deck.cards[random2] = temp;
}
/**
* Prints out the identifier of each card in the deck.
*/
public void showDeck() {
for (Card card : this.deck.cards) {
System.out.println(card.identifier);
}
}
}
GeneralPlayer.java:
/**
* An abstract class representing a general player.
*
* @param <T> the type of the value returned by the player's play method.
*/
public abstract class GeneralPlayer<T> {
/** The name of the player. */
public String name;
/**
* Creates a new GeneralPlayer with a default name.
*/
public GeneralPlayer() {
this.name = "General Player";
}
/**
* Creates a new GeneralPlayer with the given name.
*
* @param name the name of the player.
*/
public GeneralPlayer(String name) {
this.name = name;
}
/**
* Makes a move or takes an action, depending on the implementation.
*
* @return the result of the player's action or move.
*/
public abstract T play();
}
Card.java:
/**
* A class that represents a playing card with a rank and suit.
*/
public class Card {
/**
* The rank of the card which is a number from 1 to 13.
* Includes King, Queen, Jack, and Ace.
*/
private int rank;
/**
* The suit of the card which is a number from 1 to 4
* Can be clubs (), diamonds (), hearts () or spades ().
*/
private int suit;
/**
* The identifier of the card.
* It is a unique number assigned to each card based on its rank and suit.
* The identifier is calculated as suit * 100 + rank.
*/
public final int identifier;
/**
* Creates a new Card with the given suit and rank.
* It assigns the identifier as well
*
* @param suit The suit of the card.
* @param rank The rank of the card.
*/
public Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
this.identifier = suit * 100 + rank;
}
/**
* Gets the rank of the card.
*
* @return The rank of the card.
*/
public int getRank() {
return rank;
}
/**
* Sets the rank of the card.
*
* @param rank The new rank of the card.
*/
public void setRank(int rank) {
this.rank = rank;
}
/**
* Gets the suit of the card.
*
* @return The suit of the card.
*/
public int getSuit() {
return suit;
}
/**
* Sets the suit of the card.
*
* @param suit The new suit of the card.
*/
public void setSuit(int suit) {
this.suit = suit;
}
}
Table.java:
/**
* An interface representing a table where cards are played and players can
* occupy places.
*
* @param <T> the type of cards that can be added to the table.
* @param <E> the type of players that can occupy places on the table.
*/
public interface Table<T extends Card, E extends GeneralPlayer> {
/**
* The number of places on the table that players can put their cards.
*/
final int NUMBER_OF_PLACES = 4;
/**
* Adds a card to the table at the first available place.
*
* @param card the card to add to the table.
*/
public void addCardToPlace(T card);
/**
* Returns the identifiers of the cards on places 1, 2, 3, and 4 on the table
* (in that same order).
*
* @return an array of integers representing the identifiers of all cards placed on the table
*/
public int[] getPlaces();
/**
* Checks the places on the table to see if any player occupies a place and
* removes any cards that they played.
*
* @param player the player to check for occupying a place.
*/
public void checkPlaces(E player);
}
Main.java:
/**
* The Main class represents the entry point for the card game.
*/
public class Main {
/**
* The main method initializes the game and starts playing until there's a
* winner.
*
* @param args command line arguments.
*/
public static void main(String[] args) {
// Create a new deck of cards.
Deck deck = new Deck();
// Create two players and assign their names.
CardPlayer[] players = new CardPlayer[2];
players[0] = new CardPlayer("Player 1");
players[1] = new CardPlayer("Player 2");
// Create a dealer and assign the players and deck to it.
Dealer dealer = new Dealer(players, deck);
// Create a new table to place the cards on.
CardTable table = new CardTable();
// Set the first player's turn.
players[0].setTurn(true);
// Print headers for table places.
System.out.println(" CardTable Places ");
System.out.println("-------------------------");
System.out.println("| p1 | p2 | p3 | p4 |");
System.out.println("-------------------------");
int numItrs = 0; // keep track of how many iterations are played
// Play until there's a winner.
while (players[0].getHand().size() != 0 && players[1].getHand().size() != 0) {
if (players[0].isTurn()) {
// Player 1 plays a card.
table.addCardToPlace(players[0].play());
table.checkPlaces(players[0]);
// Set Player 2's turn.
players[1].setTurn(true);
} else if (players[1].isTurn()) {
// Player 2 plays a card.
table.addCardToPlace(players[1].play());
table.checkPlaces(players[1]);
// Set Player 1's turn.
players[0].setTurn(true);
}
numItrs++; // update number of iterations counter
// Show the cards on the table
System.out.printf("| %3d | %3d | %3d | %3d | n",
table.getPlaces()[0], table.getPlaces()[1], table.getPlaces()[2], table.getPlaces()[3]);
}
System.out.println("-------------------------");
System.out.println("End of game. Total #iterations = " + numItrs);
// Display each player's bank of cards:
for (CardPlayer player : players) {
System.out.println(player.bankToString());
}
// Display the winner of the game:
CardPlayer winner = players[0];
for (CardPlayer player : players) {
if (player.getPoints() > winner.getPoints()) {
winner = player;
}
}
System.out.println("The winner is: " + winner.name + " (Points: " + winner.getPoints() + ")");
}
}
Codes needed to be completed:
CardPlayer.java:
/**
* A class that represents a card player.
*
* For each card player instance, we should keep track of how many points
* they earned in the game so far, as well as whether it is their turn or not.
* Additionally, their hand and bank of cards should be stored in two
* separate ArrayLists of Card objects.
*
* <p>
* A player's points, turn, and hand of cards should all be declared
* private fields, whereas the bank of cards should be public, as follows:
* <p>
* <code>
* private int points;
*
* private boolean turn;
*
* private ArrayList&lt;Card&gt; hand = new ArrayList&lt;Card&gt;();
*
* public ArrayList&lt;Card&gt; bank = new ArrayList&lt;Card&gt;();
* </code>
* <p>
*
* Note that the Field Summary section below will only show you public fields,
* but you must declare all the fields described above in your implementation of
this class,
* including the private fields. You are free to create additional fields if deemed
necessary.
*
* @param <Card> the type of card used in the game
*/
// TODO: Create class CardPlayer.
CardTable.java :
/**
*
* This class represents a table where a game is being played.
*
* It implements the Table interface and is designed to work with Card and
* CardPlayer objects.
*
* <p>
* Each table instance must keep track of the cards that players place on the table
* during the game. The number of places available has a fixed size
(<code>NUMBER_OF_PLACES</code>),
* so we use a regular Java array to represent a CardTable's places field.
* Each entry in this places array contains
* the cards that were added to that place, which is a more dynamic structure (we
don't know
* in advance how many cards will be added to this place!).
* <p>
* Therefore, each place
* entry in this array will reference an ArrayList of Card objects.
* <p>
* Here is how to declare the array of ArrayLists field <code>places</code>:
*
* <p>
* <code>
* private ArrayList&lt;Card&gt;[] places = new
ArrayList[NUMBER_OF_PLACES];
* </code>
* <p>
*
* Note that the Field Summary section below will only show you public fields,
* but you must declare the required field places described above, which is
private.
* You are also free to create additional fields in your class implementation, if
deemed necessary.
*
*/
// TODO: Complete the implementation of class CardTable below according
// to the class documentation described here:
public class CardTable { // TODO: Fix class declaration to implement Table
interface (see documentation)
// TODO: create all required instance variables (you can add more variables
if needed)
// TODO: basic, no-argument constructor initializes all table
// places to new ArrayLists of Card objects
// TODO: implement all required CardTable methods (you can add helper methods
if needed)
}
1 Let's play cards! Problem Description and Goals Game description: In this assignment, you
will be implementing a simple game of cards. The game uses a standard 52-card deck; there are
four suits and each suit has 13 ranks. For simplicity, we use numbers to identify cards in this
assignment. Thus, we have suits 1,2, 3, and 4, and ranks from 1 to 13 (inclusive). Each card is
identified by its suit number followed by its rank. For example, card 102 refers to the card whose
suit is 1 and rank is 02 . Therefore, we can use the simple formula suit*100+rank to produce a
card's identifier. below shows the different entities involved in this game: a dealer who has a
deck of cards, two players, and a table with exactly four places where players can place their
cards during the game. Each player has a hand of cards that is private to them (i.e., not visible to
anyone else), and a bank of cards containing all cards they won during the game (visible to the
public). Figure 1: An illustration of the different entities involved in our card game. The game
begins with the dealer shuffling the deck then distributing (i.e., dealing) the cards to the two
players. The players then take turns in placing their cards on the table, one card a time, starting
with place 1 (i.e., places[0] in our array implementation), followed by place 2 , etc.; when a
player places a card in place 4 , the next player places their card in place 1 , and so on. The top
card in each place on the table is visible to everyone. Note: We use the term current place to
indicate where the current player can place their card. When a player wants to play a card, there
are two possible scenarios: 1. If there is another visible card (in places other than the current
place) whose rank is the same as the current player's card rank, then the player takes that card
from the table and adds both cards to their bank. One point is added to the player's score. 2. If
none of the visible cards (in places other than the current place) have a rank that matches the
current player's card rank, then this new card becomes the top card in the current place on the
table. No points are added to the player's score. Then, the next player plays a card, and so on.
The game continues until both players finish their cards. We then count the number of pairs of
matching cards they have collected in their banks, and the winner is the player with more pairs
(the most points). If there is a tie, then for simplicity we can consider player 1 to be the winner
(after all, this is just a simulation ;-). Sample Game: Below is the output of a sample game
(where all the rules are implemented correctly). We print the content of all 4 table places in each
iteration, with 1 indicating that no card is placed in that position: Goal: Your goal in this
assignment is to write a Java program that simulates this card game and prints the sequence of
played cards and the winner at the end, as shown above. You will take advantage of various
exciting OOP principles in Java to implement this game simulator, including inheritance,
abstraction, interfaces, generics, and ArrayList. OOP is a fantastic programming paradigm for
this game simulator, as it will help us represent and group various entities of the game in a way
that reduces code rewriting and offers modularity, encapsulation, flexibility, and reliability -
among other benefits! 2 Project Structure and Starter-Code Description You will be given
starter-code that includes fully implemented interfaces and classes (Card, Dealer, Deck,
GeneralPlayer, Table, and Main) which you are required to read and understand carefully. Then,
you will implement and submit a new class named CardPlayer which represents an individual
player. Finally, you will be given a partially implemented class named CardTable which you
need to complete and submit as well. (a) CardPlayer represents a player in this card game and it
extends the given abstract class GeneralPlayer. You are responsible for writing this class entirely
on your own, but your implementation must adhere to the full documentation given here (i.e.,
class properties, type parameters, fields, constructors, methods, etc.): (b) CardTable represents
the table where a game is being played. This class must implement the Table interface with type
parameters that enable it to work with Card and CardPlayer objects. It is partially implemented
for you; your completed implementation must adhere to the full documentation given here (i.e.,
class properties, type parameters, fields, constructors, methods, etc.):

More Related Content

Similar to Please use java to write the program that simulates the card game!!! T (1).pdf

package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfinfo430661
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfshahidqamar17
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfaggarwalshoppe14
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfaggarwalshoppe14
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdfkavithaarp
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfezzi97
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
Create the variables, and methods needed for this classA DicePlay.pdf
Create the variables, and methods needed for this classA DicePlay.pdfCreate the variables, and methods needed for this classA DicePlay.pdf
Create the variables, and methods needed for this classA DicePlay.pdfpoblettesedanoree498
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 

Similar to Please use java to write the program that simulates the card game!!! T (1).pdf (13)

package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Create the variables, and methods needed for this classA DicePlay.pdf
Create the variables, and methods needed for this classA DicePlay.pdfCreate the variables, and methods needed for this classA DicePlay.pdf
Create the variables, and methods needed for this classA DicePlay.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
 

More from admin463580

Plot total civilian unemployment from 2000 through 2021 adding in the.pdf
Plot total civilian unemployment from 2000 through 2021 adding in the.pdfPlot total civilian unemployment from 2000 through 2021 adding in the.pdf
Plot total civilian unemployment from 2000 through 2021 adding in the.pdfadmin463580
 
Plot the monthly average data presented in Table 1 onto the blank grap.pdf
Plot the monthly average data presented in Table 1 onto the blank grap.pdfPlot the monthly average data presented in Table 1 onto the blank grap.pdf
Plot the monthly average data presented in Table 1 onto the blank grap.pdfadmin463580
 
Please write an SQL query to find the city which have more than 2 ACTI.pdf
Please write an SQL query to find the city which have more than 2 ACTI.pdfPlease write an SQL query to find the city which have more than 2 ACTI.pdf
Please write an SQL query to find the city which have more than 2 ACTI.pdfadmin463580
 
Please use c++ and give screen shot of full code There are n boxes of.pdf
Please use c++ and give screen shot of full code  There are n boxes of.pdfPlease use c++ and give screen shot of full code  There are n boxes of.pdf
Please use c++ and give screen shot of full code There are n boxes of.pdfadmin463580
 
Please use c++ There are n boxes of n different items in a warehouse-.pdf
Please use c++  There are n boxes of n different items in a warehouse-.pdfPlease use c++  There are n boxes of n different items in a warehouse-.pdf
Please use c++ There are n boxes of n different items in a warehouse-.pdfadmin463580
 
please solve the following questions in the picture- Part2 - Based on.pdf
please solve the following questions in the picture- Part2 - Based on.pdfplease solve the following questions in the picture- Part2 - Based on.pdf
please solve the following questions in the picture- Part2 - Based on.pdfadmin463580
 
please solve thank you All of the following statements concerning osmo.pdf
please solve thank you All of the following statements concerning osmo.pdfplease solve thank you All of the following statements concerning osmo.pdf
please solve thank you All of the following statements concerning osmo.pdfadmin463580
 
Please solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdfPlease solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdfadmin463580
 
Please solve Question 9- 8- P the.pdf
Please solve Question 9-  8- P the.pdfPlease solve Question 9-  8- P the.pdf
Please solve Question 9- 8- P the.pdfadmin463580
 
Please show your work! Draw an UML class diagram showing the classes.pdf
Please show your work!   Draw an UML class diagram showing the classes.pdfPlease show your work!   Draw an UML class diagram showing the classes.pdf
Please show your work! Draw an UML class diagram showing the classes.pdfadmin463580
 
Please simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdfPlease simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdfadmin463580
 
Please solve (b) The frequency distribution of heights of 100 college.pdf
Please solve  (b) The frequency distribution of heights of 100 college.pdfPlease solve  (b) The frequency distribution of heights of 100 college.pdf
Please solve (b) The frequency distribution of heights of 100 college.pdfadmin463580
 
Please show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdfPlease show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdfadmin463580
 
please show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdfplease show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdfadmin463580
 
Please show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdfPlease show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdfadmin463580
 
please type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdfplease type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdfadmin463580
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfadmin463580
 
Please trace the execution of the following solution to the Dining Phi.pdf
Please trace the execution of the following solution to the Dining Phi.pdfPlease trace the execution of the following solution to the Dining Phi.pdf
Please trace the execution of the following solution to the Dining Phi.pdfadmin463580
 
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdfplease show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdfadmin463580
 
Please translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdfPlease translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdfadmin463580
 

More from admin463580 (20)

Plot total civilian unemployment from 2000 through 2021 adding in the.pdf
Plot total civilian unemployment from 2000 through 2021 adding in the.pdfPlot total civilian unemployment from 2000 through 2021 adding in the.pdf
Plot total civilian unemployment from 2000 through 2021 adding in the.pdf
 
Plot the monthly average data presented in Table 1 onto the blank grap.pdf
Plot the monthly average data presented in Table 1 onto the blank grap.pdfPlot the monthly average data presented in Table 1 onto the blank grap.pdf
Plot the monthly average data presented in Table 1 onto the blank grap.pdf
 
Please write an SQL query to find the city which have more than 2 ACTI.pdf
Please write an SQL query to find the city which have more than 2 ACTI.pdfPlease write an SQL query to find the city which have more than 2 ACTI.pdf
Please write an SQL query to find the city which have more than 2 ACTI.pdf
 
Please use c++ and give screen shot of full code There are n boxes of.pdf
Please use c++ and give screen shot of full code  There are n boxes of.pdfPlease use c++ and give screen shot of full code  There are n boxes of.pdf
Please use c++ and give screen shot of full code There are n boxes of.pdf
 
Please use c++ There are n boxes of n different items in a warehouse-.pdf
Please use c++  There are n boxes of n different items in a warehouse-.pdfPlease use c++  There are n boxes of n different items in a warehouse-.pdf
Please use c++ There are n boxes of n different items in a warehouse-.pdf
 
please solve the following questions in the picture- Part2 - Based on.pdf
please solve the following questions in the picture- Part2 - Based on.pdfplease solve the following questions in the picture- Part2 - Based on.pdf
please solve the following questions in the picture- Part2 - Based on.pdf
 
please solve thank you All of the following statements concerning osmo.pdf
please solve thank you All of the following statements concerning osmo.pdfplease solve thank you All of the following statements concerning osmo.pdf
please solve thank you All of the following statements concerning osmo.pdf
 
Please solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdfPlease solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdf
 
Please solve Question 9- 8- P the.pdf
Please solve Question 9-  8- P the.pdfPlease solve Question 9-  8- P the.pdf
Please solve Question 9- 8- P the.pdf
 
Please show your work! Draw an UML class diagram showing the classes.pdf
Please show your work!   Draw an UML class diagram showing the classes.pdfPlease show your work!   Draw an UML class diagram showing the classes.pdf
Please show your work! Draw an UML class diagram showing the classes.pdf
 
Please simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdfPlease simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdf
 
Please solve (b) The frequency distribution of heights of 100 college.pdf
Please solve  (b) The frequency distribution of heights of 100 college.pdfPlease solve  (b) The frequency distribution of heights of 100 college.pdf
Please solve (b) The frequency distribution of heights of 100 college.pdf
 
Please show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdfPlease show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdf
 
please show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdfplease show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdf
 
Please show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdfPlease show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdf
 
please type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdfplease type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdf
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Please trace the execution of the following solution to the Dining Phi.pdf
Please trace the execution of the following solution to the Dining Phi.pdfPlease trace the execution of the following solution to the Dining Phi.pdf
Please trace the execution of the following solution to the Dining Phi.pdf
 
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdfplease show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
 
Please translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdfPlease translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdf
 

Recently uploaded

Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

Please use java to write the program that simulates the card game!!! T (1).pdf

  • 1. Please use java to write the program that simulates the card game!!! Thx!!! Given codes: Dealer.java : import java.util.Random; /** * This class represents a dealer who shuffles a deck of cards and * distributes them to players. */ public class Dealer { private Deck deck; /** * Creates a new Dealer object with the specified players and deck. * * @param players the array of CardPlayer objects to distribute the cards to * @param deck the Deck object to shuffle and distribute */ public Dealer(CardPlayer[] players, Deck deck) { this.deck = deck; this.shuffle(); this.distribute(players, this.deck); } /** * Distributes the cards in the deck to the specified players.
  • 2. * * @param players the array of CardPlayer objects to distribute the cards to * @param deck the Deck object to distribute */ private void distribute(CardPlayer[] players, Deck deck) { for (int cardCounter = 0; cardCounter < deck.cards.length; cardCounter += players.length) { for (int playerCounter = 0; playerCounter < players.length; playerCounter++) { players[playerCounter].addToHand(deck.cards[cardCounter + playerCounter]); } } } /** * Shuffles the cards in the deck; it generates two random variables as the card * index and swaps them. */ private void shuffle() { Random randomNumber = new Random(); for (int card = 0; card < this.deck.cards.length; card++) { swap(randomNumber.nextInt(deck.cards.length), randomNumber.nextInt(deck.cards.length)); } } /** * Swaps the positions of two cards in the deck.
  • 3. * * @param random1 the index of the first card to swap * @param random2 the index of the second card to swap */ private void swap(int random1, int random2) { Card temp; temp = this.deck.cards[random1]; this.deck.cards[random1] = this.deck.cards[random2]; this.deck.cards[random2] = temp; } /** * Prints out the identifier of each card in the deck. */ public void showDeck() { for (Card card : this.deck.cards) { System.out.println(card.identifier); } } } GeneralPlayer.java: /** * An abstract class representing a general player. *
  • 4. * @param <T> the type of the value returned by the player's play method. */ public abstract class GeneralPlayer<T> { /** The name of the player. */ public String name; /** * Creates a new GeneralPlayer with a default name. */ public GeneralPlayer() { this.name = "General Player"; } /** * Creates a new GeneralPlayer with the given name. * * @param name the name of the player. */ public GeneralPlayer(String name) { this.name = name; } /** * Makes a move or takes an action, depending on the implementation. * * @return the result of the player's action or move.
  • 5. */ public abstract T play(); } Card.java: /** * A class that represents a playing card with a rank and suit. */ public class Card { /** * The rank of the card which is a number from 1 to 13. * Includes King, Queen, Jack, and Ace. */ private int rank; /** * The suit of the card which is a number from 1 to 4 * Can be clubs (), diamonds (), hearts () or spades (). */ private int suit; /** * The identifier of the card. * It is a unique number assigned to each card based on its rank and suit. * The identifier is calculated as suit * 100 + rank. */
  • 6. public final int identifier; /** * Creates a new Card with the given suit and rank. * It assigns the identifier as well * * @param suit The suit of the card. * @param rank The rank of the card. */ public Card(int suit, int rank) { this.suit = suit; this.rank = rank; this.identifier = suit * 100 + rank; } /** * Gets the rank of the card. * * @return The rank of the card. */ public int getRank() { return rank; } /** * Sets the rank of the card.
  • 7. * * @param rank The new rank of the card. */ public void setRank(int rank) { this.rank = rank; } /** * Gets the suit of the card. * * @return The suit of the card. */ public int getSuit() { return suit; } /** * Sets the suit of the card. * * @param suit The new suit of the card. */ public void setSuit(int suit) { this.suit = suit; } }
  • 8. Table.java: /** * An interface representing a table where cards are played and players can * occupy places. * * @param <T> the type of cards that can be added to the table. * @param <E> the type of players that can occupy places on the table. */ public interface Table<T extends Card, E extends GeneralPlayer> { /** * The number of places on the table that players can put their cards. */ final int NUMBER_OF_PLACES = 4; /** * Adds a card to the table at the first available place. * * @param card the card to add to the table. */ public void addCardToPlace(T card); /** * Returns the identifiers of the cards on places 1, 2, 3, and 4 on the table * (in that same order). *
  • 9. * @return an array of integers representing the identifiers of all cards placed on the table */ public int[] getPlaces(); /** * Checks the places on the table to see if any player occupies a place and * removes any cards that they played. * * @param player the player to check for occupying a place. */ public void checkPlaces(E player); } Main.java: /** * The Main class represents the entry point for the card game. */ public class Main { /** * The main method initializes the game and starts playing until there's a * winner. * * @param args command line arguments. */ public static void main(String[] args) {
  • 10. // Create a new deck of cards. Deck deck = new Deck(); // Create two players and assign their names. CardPlayer[] players = new CardPlayer[2]; players[0] = new CardPlayer("Player 1"); players[1] = new CardPlayer("Player 2"); // Create a dealer and assign the players and deck to it. Dealer dealer = new Dealer(players, deck); // Create a new table to place the cards on. CardTable table = new CardTable(); // Set the first player's turn. players[0].setTurn(true); // Print headers for table places. System.out.println(" CardTable Places "); System.out.println("-------------------------"); System.out.println("| p1 | p2 | p3 | p4 |"); System.out.println("-------------------------"); int numItrs = 0; // keep track of how many iterations are played // Play until there's a winner. while (players[0].getHand().size() != 0 && players[1].getHand().size() != 0) { if (players[0].isTurn()) { // Player 1 plays a card. table.addCardToPlace(players[0].play());
  • 11. table.checkPlaces(players[0]); // Set Player 2's turn. players[1].setTurn(true); } else if (players[1].isTurn()) { // Player 2 plays a card. table.addCardToPlace(players[1].play()); table.checkPlaces(players[1]); // Set Player 1's turn. players[0].setTurn(true); } numItrs++; // update number of iterations counter // Show the cards on the table System.out.printf("| %3d | %3d | %3d | %3d | n", table.getPlaces()[0], table.getPlaces()[1], table.getPlaces()[2], table.getPlaces()[3]); } System.out.println("-------------------------"); System.out.println("End of game. Total #iterations = " + numItrs); // Display each player's bank of cards: for (CardPlayer player : players) { System.out.println(player.bankToString()); } // Display the winner of the game: CardPlayer winner = players[0];
  • 12. for (CardPlayer player : players) { if (player.getPoints() > winner.getPoints()) { winner = player; } } System.out.println("The winner is: " + winner.name + " (Points: " + winner.getPoints() + ")"); } } Codes needed to be completed: CardPlayer.java: /** * A class that represents a card player. * * For each card player instance, we should keep track of how many points * they earned in the game so far, as well as whether it is their turn or not. * Additionally, their hand and bank of cards should be stored in two * separate ArrayLists of Card objects. * * <p> * A player's points, turn, and hand of cards should all be declared * private fields, whereas the bank of cards should be public, as follows: * <p> * <code> * private int points; * * private boolean turn; * * private ArrayList&lt;Card&gt; hand = new ArrayList&lt;Card&gt;(); * * public ArrayList&lt;Card&gt; bank = new ArrayList&lt;Card&gt;(); * </code> * <p> * * Note that the Field Summary section below will only show you public fields, * but you must declare all the fields described above in your implementation of this class,
  • 13. * including the private fields. You are free to create additional fields if deemed necessary. * * @param <Card> the type of card used in the game */ // TODO: Create class CardPlayer. CardTable.java : /** * * This class represents a table where a game is being played. * * It implements the Table interface and is designed to work with Card and * CardPlayer objects. * * <p> * Each table instance must keep track of the cards that players place on the table * during the game. The number of places available has a fixed size (<code>NUMBER_OF_PLACES</code>), * so we use a regular Java array to represent a CardTable's places field. * Each entry in this places array contains * the cards that were added to that place, which is a more dynamic structure (we don't know * in advance how many cards will be added to this place!). * <p> * Therefore, each place * entry in this array will reference an ArrayList of Card objects. * <p> * Here is how to declare the array of ArrayLists field <code>places</code>: * * <p> * <code> * private ArrayList&lt;Card&gt;[] places = new ArrayList[NUMBER_OF_PLACES]; * </code> * <p> * * Note that the Field Summary section below will only show you public fields, * but you must declare the required field places described above, which is private. * You are also free to create additional fields in your class implementation, if deemed necessary. * */ // TODO: Complete the implementation of class CardTable below according
  • 14. // to the class documentation described here: public class CardTable { // TODO: Fix class declaration to implement Table interface (see documentation) // TODO: create all required instance variables (you can add more variables if needed) // TODO: basic, no-argument constructor initializes all table // places to new ArrayLists of Card objects // TODO: implement all required CardTable methods (you can add helper methods if needed) } 1 Let's play cards! Problem Description and Goals Game description: In this assignment, you will be implementing a simple game of cards. The game uses a standard 52-card deck; there are four suits and each suit has 13 ranks. For simplicity, we use numbers to identify cards in this assignment. Thus, we have suits 1,2, 3, and 4, and ranks from 1 to 13 (inclusive). Each card is identified by its suit number followed by its rank. For example, card 102 refers to the card whose suit is 1 and rank is 02 . Therefore, we can use the simple formula suit*100+rank to produce a card's identifier. below shows the different entities involved in this game: a dealer who has a deck of cards, two players, and a table with exactly four places where players can place their cards during the game. Each player has a hand of cards that is private to them (i.e., not visible to anyone else), and a bank of cards containing all cards they won during the game (visible to the public). Figure 1: An illustration of the different entities involved in our card game. The game begins with the dealer shuffling the deck then distributing (i.e., dealing) the cards to the two players. The players then take turns in placing their cards on the table, one card a time, starting with place 1 (i.e., places[0] in our array implementation), followed by place 2 , etc.; when a player places a card in place 4 , the next player places their card in place 1 , and so on. The top card in each place on the table is visible to everyone. Note: We use the term current place to indicate where the current player can place their card. When a player wants to play a card, there are two possible scenarios: 1. If there is another visible card (in places other than the current place) whose rank is the same as the current player's card rank, then the player takes that card from the table and adds both cards to their bank. One point is added to the player's score. 2. If none of the visible cards (in places other than the current place) have a rank that matches the current player's card rank, then this new card becomes the top card in the current place on the table. No points are added to the player's score. Then, the next player plays a card, and so on. The game continues until both players finish their cards. We then count the number of pairs of matching cards they have collected in their banks, and the winner is the player with more pairs (the most points). If there is a tie, then for simplicity we can consider player 1 to be the winner (after all, this is just a simulation ;-). Sample Game: Below is the output of a sample game (where all the rules are implemented correctly). We print the content of all 4 table places in each iteration, with 1 indicating that no card is placed in that position: Goal: Your goal in this assignment is to write a Java program that simulates this card game and prints the sequence of played cards and the winner at the end, as shown above. You will take advantage of various exciting OOP principles in Java to implement this game simulator, including inheritance, abstraction, interfaces, generics, and ArrayList. OOP is a fantastic programming paradigm for this game simulator, as it will help us represent and group various entities of the game in a way
  • 15. that reduces code rewriting and offers modularity, encapsulation, flexibility, and reliability - among other benefits! 2 Project Structure and Starter-Code Description You will be given starter-code that includes fully implemented interfaces and classes (Card, Dealer, Deck, GeneralPlayer, Table, and Main) which you are required to read and understand carefully. Then, you will implement and submit a new class named CardPlayer which represents an individual player. Finally, you will be given a partially implemented class named CardTable which you need to complete and submit as well. (a) CardPlayer represents a player in this card game and it extends the given abstract class GeneralPlayer. You are responsible for writing this class entirely on your own, but your implementation must adhere to the full documentation given here (i.e., class properties, type parameters, fields, constructors, methods, etc.): (b) CardTable represents the table where a game is being played. This class must implement the Table interface with type parameters that enable it to work with Card and CardPlayer objects. It is partially implemented for you; your completed implementation must adhere to the full documentation given here (i.e., class properties, type parameters, fields, constructors, methods, etc.):