Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Please Tasks: First you will need to download two flies from the FYE site (next to this doc). If you are a C#

In Java Please image text in transcribed
image text in transcribed
Tasks: First you will need to download two flies from the FYE site (next to this doc). If you are a C\# student you'll want PlayingCards. cs and main.cs. If you are a Java student you'll want PlayingCards.java and Mainjava. Youll want to import (or copylpaste) these into your IDE to start. Your task is to write a new class called Poker. It will need a number of attributes and methods which are explained below: - First create a private attribute of type PlayingCards. Call it deck - Create two ArrayLists (Java) or Lists ( CH ) called hand1 and hand2. These should be of type string as each card is a string. - Write a method called dealHands(). It should take no parameters and return void. Take the first card off the deck and put it in hand1. Then take the next card off the deck and put it in hand 2. Do this until both hands have 5 cards. - Write a constructor that takes no parameters Instantiate a PlayingCard object on your deck variable. Call the shuffle() method in PlayingCard to shuffle the deck. Call the dealliands method you just wrote. - Write a constructor that takes in two ArrayLists (Java) or Lists (CHi). - Instantiate a PlayingCard object on your deck variable. - Set hand1 to the first parameter, and hand2 to the second parameter. - This constructor is used to test your later code. - Write a method called showHand which takes in an integer and returns void. If the integer is 1, show hand1, otherwise show hand2 - Print out "Player 1's hand:" - Print out each of the cards in hand1. Then print an empty line. - Print out 'Player 2 's hand' - Print out each of the cards in hand2 - See sample output below. - Write a method called countSuite, it should take in an ArrayList (Java) or List (CH) of strings (the hand). It should retum an array of integers. - Go through all the cards in the hand. For each card, extract the suite from the string (you might need string split for this). Count how many cards are clubs, and put that value into cell 0 of the array you are going to return. Count how many cards are diamonds, and put that value into cell 1 of the array. Count the Hearts and put that into cell 2 . Finally count the spades and put that value into cell 3. Return the array of integers which has the count of how many each suite you have. This will be useful when you check for flushes. - Write a method called countValues. It should take in an ArrayList (Java) or List (CH) of strings (the hand). It should return an array of integers. Create an array of size 14. Extract the value out of each card in the hand. Use the array to keep track of how many of each value you see. For example if you have an Ace (A) increment cell 1 of the array. If you have a card with a 6 you'd increment the value in cell 6 of the array. Increment cell 11 for Jack (J), cell 12 for Queen (Q) and cell 13 for King (K). Return the array. - Write a method called numPairs which takes in an array of integers the one you got back from countValues). It will return an integer. Look through the array for any cell which has a 2 in it. Each cell that has a 2 indicates you have a pair. Return the number of pairs you found. - Write a method called threeOtAKind which takes in an array of integers (the one you got back from countValues). It returns an int. It should look through the array and see if any cell has a 3 in it, indicating there are 3 of that value. If so, return the cell number that has the 3 in it. Otherwise return 0. - Write a method fourOtAKind which works the same as threeOtAKind but looks for a cell with 4 in it. - Write a method called fullHouse. It should take in an array of integers (the one you got back from countValues). It returns a boolean. Check if you have threeOtAKind and one pair. You have methods for checking each of these conditions. If yes, return true, otherwise false. - Write a method called straight. It should take in an array of integers (the one you got back from countValues). It returns a boolean. You'li need to see if there are sequential cells in the array with a 1 in them. This would indicate that you have a straight. You'll also need to check for the one odd straight where you have a 10,J,Q,K, A. This is odd, because the 10 is in cell 10,J in 11,Q in 12,K in 13 , but the A is in cell 1. - Write a mothod called flush. It should take in how many clubs, diamonds, hearts and spades you have in the hand. If any of those values are 5, return true, otherwise false. - Write a method called straightFlush. It should take in an array of integers (the one you got back from countValues) as well as the number of clubs, diamonds, hearts and spades in the hand. Then simply check if you have both a straight and a flush. You have methods for each. If they are both true, return true, otherwise false. - Write a method called royalFlush which takes in the array of integers you got back from countValues, followed by the number of clubs, diamonds, hearts and spades you have. This method should return a boolean (Java) or bool (CH). If you have 5 clubs, 5 diamonds, 5 hearts or 5 spades and cells 10, 11, 12, 13 and 1 of the array have a 1 in them, you have a royal flush, otherwise you don't. - Write a method called scoreHand which takes in an integer and returns a string. The method will return a string which contains the strength of the hand. If the passed in parameter is 1, this method will return the strength of hand1. otherwise it'll return the strength of hand2. - To determine the strength, start at the strongest hand (royal flush) and check if the hand qualifies, then try the next strongest. If none qualfy youll retum "High Card

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

What are some of Samsungs greatest competitive strengths?

Answered: 1 week ago