SlideShare a Scribd company logo
1 of 16
Download to read offline
Here is the game description:
Here is the sample game:
Here is the requirement:
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. Use
Dealer.java, GeneralPlayer.java, Main.java, Card.java, Table.java, and Deck.java, complete
CardPlayer.java and CardTable.java.
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:
// https://www.cs.emory.edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardTable.html
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)
}
Requirement of submission: Finish CardPlayer.java and CardTable.java without changing any
other given code, to successfully generate a game with Main.java.
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 sssignment. Thus, we have suits 1,2, 3, and 4,
and rarks from 1 to 13 (inclusive). Fach 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. Figure - 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. 1 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 2 Player 1 bank has 10 carda: 401 101402 302 109409404204412112 playar 2 bank has
4 carda: 208 308 106206 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. Important: Start by carefully reading and understanding the
completed Java files given to you first, before moving on to the parts that you need to
implement. To make your job easier, we generated a comprehensive documentation of all classes
and interfaces in our assignment. package, available here: https://www.cs. emory, edu/
nelsay2/cs171_s 23/ a 2/ doc / index.htm1. Please read it very carefully and let us know during
office hours or Piazza if you have any questions! More details about Main.java: This class will
help you test your code and make sure that your implementation of CardPlayer and CardTable
are correct. In the main method, a new Deck object 3 is created to represent the deck of cards
used in the game. Two CardPlayer objects are created. A Dealer object is created and the players
and deck are assigned to it. And a CardTable object. is created to represent the table in the game.
The first player's turn is set to true and the game loop begins. The loop will continue as long as
both players have cards in their hands. When it is a player's turn and their card is played (i.e.,
placed on the table), the proper methods from class CardTable are called in Main to check if the
ranks of other cards on the table are a match to the newly placed card or not, and so on. After
each player turn, the cards on the table are displayed. Once the game loop is finished, each
player's bank of cards is displayed, followed by the declaration of the winner. Note that the
methods that you will implement in other classes will be called in class Main. This can help you
test and debug your code. Required Classes: CardPlayer.java and CardTable.java. These are the
two (and only) classes that you need to submit on Gradescope for this assignment. (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.): ht.tns://www.cs.emory. edn/-na1say2/c.s171_s23/a2/dnc/c.s171a2/CardP1ayer.
html. (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.): httons://www.cs.emory edn/ ne1
say2/cs171_s23/a2/doc/cs171a2/CardTable.html.
Here is the game description- Here is the sample game- Here is the req.pdf

More Related Content

Similar to Here is the game description- Here is the sample game- Here is the req.pdf

Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
adwitanokiastore
ย 
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
asif1401
ย 
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
ezzi97
ย 
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
kavithaarp
ย 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
agarvalcollections16
ย 
Code em Poker
Code em PokerCode em Poker
Code em Poker
Ankit Gupta
ย 
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
shahidqamar17
ย 
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
contact41
ย 

Similar to Here is the game description- Here is the sample game- Here is the req.pdf (10)

Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
ย 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
ย 
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
ย 
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
ย 
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
ย 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .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
ย 
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
ย 
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
ย 

More from trishulinoverseas1

Hi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdfHi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdf
trishulinoverseas1
ย 
here is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdfhere is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdf
trishulinoverseas1
ย 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
trishulinoverseas1
ย 
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdfHomework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
trishulinoverseas1
ย 

More from trishulinoverseas1 (20)

Hi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdfHi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdf
ย 
hey guys do fill the t accounts out of it in the below screenshot att.pdf
hey guys  do fill the t accounts out of it in the below screenshot att.pdfhey guys  do fill the t accounts out of it in the below screenshot att.pdf
hey guys do fill the t accounts out of it in the below screenshot att.pdf
ย 
Hi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdfHi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdf
ย 
Hi Expert ! could you please type the answers to see better! microbio.pdf
Hi Expert !  could you please type the answers to see better! microbio.pdfHi Expert !  could you please type the answers to see better! microbio.pdf
Hi Expert ! could you please type the answers to see better! microbio.pdf
ย 
Hey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdfHey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdf
ย 
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdfHhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdf
ย 
here is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdfhere is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdf
ย 
Here- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdfHere- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdf
ย 
Here are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdfHere are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdf
ย 
Here is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdfHere is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdf
ย 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
ย 
Here is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdfHere is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdf
ย 
Here are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdfHere are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdf
ย 
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdfHomework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
ย 
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdfHot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdf
ย 
Housing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdfHousing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdf
ย 
hotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdfhotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdf
ย 
Herb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdfHerb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdf
ย 
Homework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdfHomework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdf
ย 
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdfHomework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
ย 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
ย 
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ไธญ ๅคฎ็คพ
ย 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
MirzaAbrarBaig5
ย 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
ย 
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
cupulin
ย 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
ย 
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ไธญ ๅคฎ็คพ
ย 

Recently uploaded (20)

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
ย 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
ย 
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
ย 
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡ๆœƒ่€ƒ่‹ฑๆ–‡
ย 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
ย 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
ย 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
ย 
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
ย 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
ย 
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
ย 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
ย 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
ย 
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
ย 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
ย 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
ย 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
ย 
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
ย 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
ย 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
ย 
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝๆœƒ่€ƒ่‹ฑ่ฝ
ย 

Here is the game description- Here is the sample game- Here is the req.pdf

  • 1. Here is the game description: Here is the sample game: Here is the requirement: 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. Use Dealer.java, GeneralPlayer.java, Main.java, Card.java, Table.java, and Deck.java, complete CardPlayer.java and CardTable.java. 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();
  • 2. 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));
  • 3. } } /** * 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); } } }
  • 4. 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; }
  • 5. /** * 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; /**
  • 6. * 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() {
  • 7. 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. */
  • 8. 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);
  • 9. /** * 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.
  • 10. * * @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.
  • 11. 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) {
  • 12. 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;();
  • 13. * * 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> *
  • 14. * 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: // https://www.cs.emory.edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardTable.html 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) } Requirement of submission: Finish CardPlayer.java and CardTable.java without changing any other given code, to successfully generate a game with Main.java. 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 sssignment. Thus, we have suits 1,2, 3, and 4, and rarks from 1 to 13 (inclusive). Fach 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. Figure - 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. 1 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
  • 15. 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 2 Player 1 bank has 10 carda: 401 101402 302 109409404204412112 playar 2 bank has 4 carda: 208 308 106206 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. Important: Start by carefully reading and understanding the completed Java files given to you first, before moving on to the parts that you need to implement. To make your job easier, we generated a comprehensive documentation of all classes and interfaces in our assignment. package, available here: https://www.cs. emory, edu/ nelsay2/cs171_s 23/ a 2/ doc / index.htm1. Please read it very carefully and let us know during office hours or Piazza if you have any questions! More details about Main.java: This class will help you test your code and make sure that your implementation of CardPlayer and CardTable are correct. In the main method, a new Deck object 3 is created to represent the deck of cards used in the game. Two CardPlayer objects are created. A Dealer object is created and the players and deck are assigned to it. And a CardTable object. is created to represent the table in the game. The first player's turn is set to true and the game loop begins. The loop will continue as long as both players have cards in their hands. When it is a player's turn and their card is played (i.e., placed on the table), the proper methods from class CardTable are called in Main to check if the ranks of other cards on the table are a match to the newly placed card or not, and so on. After each player turn, the cards on the table are displayed. Once the game loop is finished, each player's bank of cards is displayed, followed by the declaration of the winner. Note that the methods that you will implement in other classes will be called in class Main. This can help you test and debug your code. Required Classes: CardPlayer.java and CardTable.java. These are the two (and only) classes that you need to submit on Gradescope for this assignment. (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.): ht.tns://www.cs.emory. edn/-na1say2/c.s171_s23/a2/dnc/c.s171a2/CardP1ayer. html. (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.): httons://www.cs.emory edn/ ne1 say2/cs171_s23/a2/doc/cs171a2/CardTable.html.