//implementing poker class
public class poker
{
//implementing bridgeHandShape method to return
string of counted Spades,hearts,diamonds and clubs
public String bridgeHandShape(String hand)
{
//declaring
variables
int i,len,num[]={0,0,0,0};
String
str="";
//calculating length of string
hand
len=hand.length();
//System.out.println("length is
"+len);
//counting Spades,hearts,diamonds
and clubs for given string using switch and case
for
(i=0;i<len;i++)
{
switch(hand.charAt(i))
{
case 's' :
case 'S' : num[0]++;break;
case 'h' :
case 'H' : num[1]++;break;
case 'd' :
case 'D' : num[2]++;break;
case 'c' :
case 'C' : num[3]++;break;
}
}
//assigning count of all into a
string
for (i=0;i<4;i++)
{
// System.out.println("count is "+num[i]);
str+=num[i];
if(i<3)
str+=", ";
}
//returning string to called
function
return str;
}
//implementing hasfullhouse() method
public boolean hasFullHouse(String hand)
{
boolean
hfs=false;
int i,len,rank[]={0,0};
len=hand.length();
//taking first card into cr1
char
cr1=hand.charAt(0);
char cr2=cr1;
for (i=0;i<len;i=i+2)
{
//counting number of first cards
if(cr1==hand.charAt(i))
rank[0]++;
else
cr2=hand.charAt(i);
//getting second card as cr2 if not equal to first
card
}
// System.out.println("cr1
"+cr1+" cr2"+cr2);
for
(i=0;i<len;i=i+2)
{
//counting number of second cards
if(cr2==hand.charAt(i))
rank[1]++;
}
//if house full then only hfs is
true
if((rank[0]==3&&rank[1]==2)||(rank[1]==3&&rank[0]==2))
hfs=true;
return hfs;
//returning hfs into called method
}
//main method implementation
public static void main(String []args)
{
//creating object to access methods of poker class
poker obj=new
poker();
//assigning strings to variables
String str1=
"Kh6c2cJdjcAd7h3d8dQdTsTh3h",str2="Jh6c6cJdJc";
//calling functions and displaying results
System.out.println("Returned string of
counting Spades,hearts,diamonds and clubs is
"+obj.bridgeHandShape(str1));
System.out.println("Fullhouse is "+obj.hasFullHouse(str2));
}
//end of main
}
//end of poker class
//output screen shot is shown below including some portion of program
java programming 3. Back to contract bridge. The shape of the hand (that is, how "balanced"...
Python Programming: An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded as letter T to make all card ranks to be single letters) • the second character is from "cdhs" and represents the suit (clubs, diamonds, hearts and spades respectively). For example, "Jd" would be the jack of diamonds, and "4s" would be...
Assume you are dealt the following hand in poker: K of hearts, Q of hearts, 10 of spades, 3 hearts, 7 clubs. For this set of problems, we are keeping both the K and Q of hearts. So, If you keep the King and Queen of hearts find: P (getting a pair of Kings and/or Queens)…be sure to exclude the probability of getting either three or four Kings or Queens. Also consider the probability of one or two pairs. P(3...
Assume you are dealt the following hand in poker: K of hearts, Q of hearts, 10 of spades, 3 hearts, 7 clubs. For this set of problems, we are keeping both the K and Q of hearts. So, If you keep the King and Queen of hearts find: P (getting a pair of Kings and/or Queens)…be sure to exclude the probability of getting either three or four Kings or Queens. Also consider the probability of one or two pairs. P(3...
Assume you are dealt the following hand in poker: K of hearts, Q of hearts, 10 of spades, 3 hearts, 7 clubs. Suppose you decide to keep the King of hearts and the Queen of Hearts, and the 3 of hearts, find: - P(flush in hearts) - P(pair of Kings or a pair of Queens or a pair of both Queens and Kings) - P(3-Kings or 3-Queens) as far as how many cards are left to be selected from, assume...
Learning objectives 1. To implement decisions using if statements 2. To write statements using the boolean primitive data type. 3. To compare strings and/or characters. 4. To write loops using while or for. 5. To write functions Representing playing cards and hands of cards An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded...
This activity needs to be completed in the Python language. This program will simulate part of the game of Poker. This is a common gambling game comparing five-card hands against each other with the value of a hand related to its probability of occurring. This program will simply be evaluating and comparing hands, and will not worry about the details of dealing and betting. Here follow the interesting combinations of cards, organized from most common to least common: Pair --...
1. (25 total points) Probability and card games; Recall that an ordinary decdk of playing cards has 52 cards of which 13 cards are from each of the four suits hearts, diamonds, spades, and clubs. Each suit contains the cards 2 to 10, ace, jack, queen, and king. (a) (10 points) Three cards are randomly selected, without replacement, from an or- dinary deck of 52 playing cards. Compute the conditional probability that the first card selected is a spade, given...
Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! !!!!!!!!!!!!!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!!!!!!!!!!!!!!!!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in new deck order. (This is the order of a deck of cards new from the box.) The 2 Array lists...
C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....