Homework Four: 3 Card Poker (Simplified) For this programming project, you will develop three java object classes. You must work individually on this project. You may consult only a Siena CS faculty member or the official Siena CS tutors for help. You may not discuss the program with anyone else including your classmates until after everyone has submitted their programs. Have fun and good luck! Homework4 Project There are two real world entities we are looking to represent: Player and Game. This project should contain two Objects classes and one PlayGame class, with just a main method. The PlayGame class will create several players, a game, and keep playing that game with the player objects until the user chooses to quit. The PlayGame class will be used to demonstrate the functionality of your project. One of the two objects is the Player class, which contains all the data and methods needed to represent and manipulate a single instance of a Player. The second is the Game object, which contains all of the data and methods needed to represent and manipulate a single instance of a Game. The game will be a modified version of 3 card poker. Winner is determined as follows: • • • Three of a kind beats pair (if both players have 3 of a kind, then highest card value of set wins) Pair beats high card (if both players have 2 of a kind, then highest card value of pair wins) High card (if neither player has a pair nor three of a kind, the player with the highest value card wins) Player Class Each player is represented by an instance of the Player class, which records a player’s name, number of game wins, and number of game losses. There should be a constructor and appropriate getters and setters for each of the class instance variables. Additionally, the following methods should be created: toString – returns a String containing all player information in a nice format. addWin – increases number of game wins by 1 addLoss – increases number of game losses by 1 Game Class Each game is represented by an instance of the Game class, which contains two players (i.e. two Player objects) and a set of randomly selected cards (i.e. Array of random int card values). Do not create any other instance variables, use local variables and pass as arguments when needed. There should be a constructor and appropriate getters and setters for each of the class instance variables. Additionally, the following methods should be created: Methods: populateCards Populate cards array instance variable with 6 cards of random value. Valid card values are 1-13 (i.e.1 is Ace, 11 is Jack, 12 is Queen and 13 is King). dealHand Method accepts one parameter (i.e. dealOrder) that can either be 1 or 2. The method will deal a hand by populating an array of 3 card values (i.e. a hand) from the cards array of 6 cards. If dealOrder is 1, then player's hand starts with the first card in the cards array. If dealOrder is 2, then player's hand starts with the second card in the cards array. They are then dealt every other card from the cards array. Finally, the method should return the hand array of 3 cards. getMaxCard Helper method called by determineWinner method that accepts a hand array as a parameter. Get and return the value of the highest card in a player's hand. printHand Accepts a hand array as a parameter. The method prints the card values in the hand, all on one line and separating each card value with a comma. There should be no comma at the end. determineWinner Accepts two hand arrays as parameters (i.e. player 1’s hand and player 2’s hand) and determines the winning player. If neither player has a pair nor three of a kind, the helper method getMaxCard is called to determine which player has the highest card. Once winner is determined, the method then updates the wins and losses for both players and returns the winning player. Note: You may create additional helper methods as you deem appropriate. © Meg Fryling 2015 PlayGame Class Your PlayGame class will contain a single main method that will do the following: 1) Create two Player instances 2) Create a Game instance. 3) While the user wants to keep playing, call the appropriate Game methods to deal hands for both players. 4) Print the hand values for both players. 5) Call the appropriate Game method to check for a winner. If tie, then print "PUSH - No winner this time!" Otherwise, print the name of the winner and the fact that they won (e.g. "Jane Doe WINS!"). 6) Print the stats for each player using the toString Player method. Submitting your Work The two things you need to do to complete the submission: 1) Check the Grading Rubric below and make sure you have done everything. 2) Zip your entire Homework4 BlueJ project and upload the zipped file to Blackboard. Feature Value Your Score STYLE 20 Comments (full class for Game and Player) Proper Variable Names Proper Indenting, Spacing etc Player Class 20 Class variables/getters/setters toString method addWin method addLoss method Game Class 45 Class variables/ getters / setters populateCards method dealHand method getMaxCard method printHand method determineWinner method PlayGame Class 15 Plays game with two players and repeats as long as user wishes to continue. Output format is coherent and readable HOMEWORK 4 TOTAL 100 © Meg Fryling 2015
© Copyright 2024