Question: CS 171: Introduction to Computer Science II Assignment #2 (Advanced OOP): A Card Game Due: Friday, March 3 at 11,59 PM EST on Gradescope [Late


![Gradescope [Late Submission: See Syllabus for policy details.] Note: You can optionally](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/670ff1bbe5e19_171670ff1bbc9ee4.jpg)


CS 171: Introduction to Computer Science II Assignment #2 (Advanced OOP): A Card Game Due: Friday, March 3 at 11,59 PM EST on Gradescope [Late Submission: See Syllabus for policy details.] Note: You can optionally work in pairs for this assignment. Iflinly one student should submit the required files on IS'rradescope while indicating who your partner is. Additionally, please include both student names in the honor code at. the beginning of all submitted Java les. 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 card deck; there are four suits and each suit has 13 Tanks. 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 identied by its suit number followed by its rank. For example, card 102 refers to the card whose suit is 1 and rank is {12. Therefore, we can use the simple formula suitOO-l-I'auk to produce a card's identier. m below shows the dilierent entities involved in this game: a dealer who has a deck of cards, twu players, and a table with exactly four places where players can place their cards during the garlic. Each player has a hand of cards that is private to them le, not visible to anyone else}, and a bank of cards containing all cards they won during the game {visible to the public). Dealer Ca rdTable bank hand g g] hand s? - o [4-7 1% Ca rdPlayer CardPlaysr plateau] FIHEESIE'I Figure 1: An illustration of the different entities involved in our card game. The game begins with the dealer shufing 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[] 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 pla},r 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 nish their cards. \"re then count the number of pairs of matching cards they,r 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,r we can consider player 1 to be the winner [after all, this is just a simulation ;J. 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 p aced in that position: CardTable Places | 101 1 1 I 1 I 101 104 -1 I -1 Hatched ranks: 101 {on table) and 401 {Player 1's card} I -1 104 -1 I -1 I -1 104 -1 I 306 I 413 104 -1 I 306 I 413 30? -1 I 306 I 413 30? 310 I 306 I 413 30? 310 I 103 I 311 30? 310 I 103 I 311 302 310 I 103 I 311 302 40? I 103 I 311 302 40? I 213 Hatched ranks: 302 {on table) and 402 {Player 1's card} I 311 30? 40? I 213 I 311 201 40? I 213 I 311 201 406 I 213 I 311 201 406 I 103 I 411 201 406 I 103 I 411 205 406 I 103 I 411 205 308 I 103 I 411 205 308 I 10? I 303 205 308 I 10? I 303 403 308 I 10? Hatched ranks: 409 {on table) and 103 {Player 1's card} I 303 205 308 I 10? I 303 205 308 I 210 I 403 205 308 I 210 Hatched ranks: 308 {on table) and 203 (Player 2's card} I 403 205 406 I 210 I 403 205 204 I 210 I 403 205 204 I 312 Hatched ranks: 204 {on table) and 404 (Player 1's card} I 403 205 406 I 312 | 403 | 111 | 405 | 312 | | 403 | 111 | 113 | 312 | | 403 | 111 | 113 | 301 | | 110 I 111 I 115 I 301 I | 110 | 20? | 113 | 301 | | 110 | 20? | 313 | 301 | | 110 | 20? | 313 | 212 | | 202 | 20? | 313 | 212 | | 202 I 211 I 313 I 212 I | 202 I 211 I 105 I 212 I | 202 I 211 I 105 I 203 I | 309 I 211 I 105 I 203 I | 309 | 102 | 105 | 203 | | 309 | 102 | 304 | 203 | | 309 | 102 | 304 | 405 | | 200 | 102 | 304 | 405 | | 200 | 112 | 304 | 405 | Hatched ranks: 112 (on table) and 412 (Player 1's card) I 200 | 102 | 304 I 405 I Hatched ranks: 205 (on table) and 106 (Player 2's card) I 300 | 102 | 304 I 405 I I 410 | 102 | 304 I 405 I I 410 | 203 | 304 I 405 I I 410 | 203 | 408 I 405 | End of game. Total #iterations = 51 Player 1 bank has 10 cards: 401 101 402 302 109 409 404 204 412 112 Player 2 bank has 4 cards: 203 300 106 200 The winner is: Player 1 (Points: 5) 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. Yen will take advantage at various exciting 001' principles in Java to implement this game simulator, including inheritance, abstractiori, interfaces, generics, and ArrayList. GOP 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, exibility, and reliability,r among other benets! 2 Project Structure and Starter-Code Description You will be given startercode that includes fully implemented interfaces and classes (Card, Dealer, Deck, GeneralPlayer, Table, and Edam} which you are required to read and understand carefully. Then, you will implement and submit a new class named CardPlayc-r which represents an indi 1sidual 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 les given to you rst, before moving on to the parts that you need to implement. To make your job cas icr, we generated a comprehensive documentation of all classes and interfaces in our assignment package, available here: https: ffwwms.emery.eduf"nelsay23cs1?1_s23!a2{doca'indELhtmI. Please read it 1veryr carefully and let us know during eice 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 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 Gen- eralPlayer. 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.): https:/ /www. cs . emory . edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardPlayer . 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 doc- umentation given here (i.e., class properties, type parameters, fields, constructors, methods, etc.): https://www. cs. emory . edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardTable. html
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
