Programming Assignment4 OverviewThe goals of thissectionare to:1.Use methods2.Break down a problem into small tasks to implementSetupThis assignment requires one starter file. Set up your directory via:$ mkdir HW4$ cd HW4$ cp/home/linux/ieng6/cs11wb/public/HW4/*.Poker(40 pts)By the end of this assignment you will have created a program that cancompare two pokerhands and declare a winner.If you’ve never played poker, reviewwikipediafor the list ofwinning hands (in order):straight flushfour of a kindfull houseflushstraightthree of a kindtwo pairone pairhigh cardWe will be storing both the card values and suits in arrays. Valueswill range from:NumberRepresentationCardValue1A (Ace)22334455667788 99101011J (Jack)12Q (Queen)13K (King)And suits will be stored with chars:CharRepresentationSuitValueSSpadesDDiamondsHHeartsCClubsStep 1(5 pts):enter a hand of cardsAllow the user to input the hand of a single player. You must store this into arrays. My solutionused 2 arrays, one for the card value and one for the card suit. It should lookexactlylike this:Enter Player1’s cards:1 S 2 C 10 D 12 H 13 DThis hand represents:Ace of spades, 2 of clubs, 10 of diamonds, Queen of hearts, and King of diamonds.Note: it is safe to assume that we will only enter numbers between 1–13 and we will onlyenter characters S, D, H, and C. When we test your code, we will follow the rules of input, so itis not necessary to check for bad input.Step 2 (5 pts): print player’s cardsPrint out the cards of the player. This should happen in its own method. Your code should nowresult inexactlythe following:Enter Player 1’s cards:1 S 2 C 10 D 12 H 13 DPlayer 1’s hand:AS 2C 10D QH KDStep 3 (15pts):Discover player’spoker handPrint outthe hand of the player, e.g. FULL HOUSE, FOUR OF A KIND, etc. You should select thebest hand. That is, if a player has 3 queens and 2 jacks, you would say they have a FULL HOUSE,notthree of a kind. You should create methods to test for each possible hand. This will result in8 methods (high carddoes not require a method).Don’t forget the Ace can be highorlow in arun, e.g. A, 2, 3, 4, 5 is a straight, and 10, J, Q, K, A also counts as a straight.Critical at this point: cards will be entered innumerical order, e.g. 1, 2, 3, … 11, 12, 13.This isHUGEand will be a key assumption thatyou can follow in your program, and will make thisprogram much easier. This is my gift to you.Here’s some example runs. Make sure your code prints out these exact hands, this is how we’llbe testing your code.Enter Player 1’s cards:1 S 2 C 10 D 12 H 13 DPlayer 1’s hand:AS 2C 10D QH KDBest hand: HIGH CARDEnter Player 1’s cards:1 S 2 S3 S 4 S 5 SPlayer 1’s hand:AS 2S 3S 4S 5SBest hand: STRAIGHT FLUSHEnter Player 1’s cards: 1 D 10 C 11 S 12 H 13 HPlayer 1’s hand:AD 10C JS QH KHBest hand: STRAIGHTEnter Player 1’s cards: 10 D 10 H 10 C 13 H 13 DPlayer 1’s hand:10D 10H 10C KH KDBest hand: FULL HOUSEEnter Player 1’s cards:2 C 2 H 5 D 11 D 11 CPlayer 1’s hand:2C 2H 5D JD JCBest hand: TWO PAIRStep 4 (10 pts):Allow a 2ndplayer to enter their cards, print cards and handThis will happen in the same fashion as player 1. You should not need to duplicate code to dothis, make sure you’re using methods. If we seeduplicated code, we will deducthalf points forthis section. Your code should now look like this:Enter Player 1’s cards: 1 S 2 S 3 S 4 S 5 SPlayer 1’s hand:AS 2S 3S 4S 5SBest hand: STRAIGHT FLUSHEnter Player 2’s cards: 2 C 2 H 5 D 11 D 11 CPlayer 2’s hand:2C 2H 5D JD JCBest hand: TWO PAIRStep 5 (5 pts):Print the winner or tiePrint the player that has the winning hand. If both players have the same hand, e.g. bothplayers have a full house, print there’s a tie. This isn’t what happens in poker, but I’mmakingthe decision to make this part of the assignment easier, so just print“Tie”. Here’s someexample runs.Enter Player 1’s cards: 1 S 2 S 3 S 4 S 5 SPlayer 1’s hand:AS 2S 3S 4S 5SBest hand: STRAIGHT FLUSHEnter Player 2’s cards: 2 C 2 H 5 D 11 D 11 CPlayer 2’s hand:2C 2H 5D JD JCBest hand: TWO PAIRPlayer 1 wins!Enter Player 1’s cards: 1 S 2 S 3 S 4 S 5 SPlayer 1’s hand:AS 2S 3S 4S 5SBest hand: STRAIGHT FLUSHEnter Player 2’s cards: 1 D 10 D 11 D 12 D 13 DPlayer 2’s hand:AD 10D JD QD KDBest hand: STRAIGHT FLUSHTie!Programmer of the week(optional)If you’d like to compete in the programmer of the week challenge, you must complete theabove part of the assignment as described. Once you get that to work, create another class,POWeek.java, and start to extend the poker game. If you know howto use javafx or java.swing,you could include graphics. You could implement betting, support multiple players, allow forcards being dealt instead of being input by the user, handle ties, change to Texas hold ‘em, etc.Your tutor will present your submission at our weekly meeting and we’ll vote for the top 5submissions from each class and show those to the students to vote for the programmer of theweek. The winner will get an award, 1% extra credit added to their final grade, and be famousfor a week.Note: we will only be looking at the running of the code, i.e.we will not count offfor anything done in the POWeek.java submission.Style Requirements(10 pts)–Different from other assignmentsYou will be graded for the style of programming on this assignment.We are adding javadoccomments as a requirement to the assignment.Use reasonable commentsto make your code clear andreadable.(New)All methods must have javadoc comments. We will betesting this by running“javadoc filename.java” and ensuring that the resulting documentation pages appear.Usereasonable variable namesthat are meaningful.Use static finalconstants to make your code as general as possible. No hardcodingconstant values inline (no magic numbers).oNote(new): There will be many cases in this homework where you want tocompare card 1 to card 2, card 2 to card 3, etc. I’m allowing you to hardcodenumbers for this.Judicious use of blank spacesaround logical chunksof code makes your code mucheasier to read and debug.Keep all linesless than 80 characters.Make sure each level of indentation lines upevenly.Every time you open a new block of code (use a ‘{‘),indent farther by 2 spaces. Go backto the previous level of indenting when you close the block (use a ‘}’).Always recompile and run your program right before turning it in, just in case youcommented out some code by mistake.Turnin InstructionsRemember the deadline to turn in your assignment isSaturday, January 30by 11:59pm.When you are ready to turn in your program in, typein the following command and answer theprompted questions:$ cd ~/$bundleP4Good; all required files are present:HW4Do you want to go ahead and turninthese files? [y/n]yOK. Proceeding.Performing turnin of approx.6144bytes (+/-10%)Copying to /home/linux/ieng6/cs11wb/turnin.dest/cs11wb.P4…Done.Total bytes written:31744Please check to be sure that’s reasonable.Turnin successful.     [removed]       Part 1: PokerPts forCorrectStep 1. Are you prompted to enter a hand? Can you enter in thefollowing hand:1 S 10 C 11 D 12 C 13 SAll or no points for this.5Step 2: Double check the output for each of these hands:1 S 10 C 11 D 12 C 13 S ==>AS 10C JD QC KS1 D 1 C 8 S 9 H 11 HAD AC 8S 9H JH-1 pt for each letter missed, e.g. 1 not converted to A.5Step 3: Test each hand and result (-1 for each one wrong):1 S 10 S 11 S 12 S 13 S ==> Straight Flush1 S 2 S 3 S 4 S 5 S ==> Straight Flush1 S 10 S 11 S 12 S 13 D ==> Straight1 S 9 S 11 S 12 S 13 S ==> Flush1 S 1 D 1 H 1 C 2 C = 4 of a kind1 S 2 S 2 D 2 C 2 H = 4 of a kind1 S 1 H 1 D 2 C 2 D = Full house1 S 1 H 2 D 2 C 2 S = Full house1 S 1 D 1 H 2 C 3 S = 3 of a kind1 S 2 C 2 D 2 H 3 S = 3 of a kind1 S 2 C 3 S 3 D 3 H = 3 of a kind1 S 1 D 2 S 2 D 3 C = 2 pair1 S 1 D 2 S 3 C 3 S = 2 pair1 S 2 C 2 D 3 S 3 D = 2 pair1 S 1 D 2 C 3 D 4 H = 1 pair1 S 2 D 2 C 3 D 4 H = 1 pair1 S 2 D 3 C 3 D 4 H = 1 pair1 S 2 D 3 C 4 H 4 C = 1 pair1 S 2 C 4 C 5 D 6 H = High Card15Step 4: Can you enter a 2nd player’s hand? (2 pts)Does the 2nd players hand print as expected (2 pts – see above forexamples)Does the correct hand show up (1 pt – see above for example)How much duplicated code is there to get this step to work? (-1 ptfor each major section of duplicated code. Max of -5)10Step 5: Comparing hands. Run the following tests (-1 for eachwrong):P1: 1 S 10 S 11 S 12 S 13 SP2: 1 S 2 S 3 S 4 S 5 SResult: Tie!P1: 1 S 10 S 11 S 12 S 13 SP2: 1 S 2 S 3 S 4 S 5 DResult: Player 1 WinsP1: 1 S 9 S 11 S 12 S 13 SP2: 1 S 1 D 2 C 3 D 4 HResult: Player 1 WinsP1: 1 S 2 S 2 D 2 C 2 HP2: 1 S 1 H 1 D 2 C 2 DResult: Player 1 WinsP1: 1 S 2 C 4 C 5 D 6 HP2: 3 D 7 C 8 H 10 D 12 DResult: Tie!5COMMENTSTotal40Description (Deduct up to Twice for Each Infraction up to 10points)Pts forCorrectPart 3: Style Requirements (10 points)-1 point for each missing class/file header (only has to be one orother, They don’t need a file & class header)-1 point for each missing method header. They must be in javadocformat. /** */ with @param and @return if used in the method.-2 point for no inline comments-1 point for each meaningless variable name-1 point for each hardcoded constant besides standard 0-4 asoutlined in HW writeup. For this assignment they can do card[0]== card[4].-2 point for no logical blank space separators-1 point for each line over 80 characters-1 point for each line indented incorrectlyMake sure you find all style errors and report them to yourstudents, even if they have hit the 10 points deduction limit.An example of how to deduct points. Let’s say there are 10 linesthat go over 80 characters and everything else is great. Theywould loose 2 points total and get 8 pts for style10COMMENTSTotal10Total Score50


Source link

Leave a Reply

Your email address will not be published.