Question
public class play { public static final int ONE_PAIR = 1000000; public static final int TWO_PAIRS = 2000000; public static final int THREE_OF_A_KIND = 3000000;
public class play
{
public static final int ONE_PAIR = 1000000;
public static final int TWO_PAIRS = 2000000;
public static final int THREE_OF_A_KIND = 3000000;
public static final int STRAIGHT = 4000000;
public static final int FLUSH = 5000000;
public static final int FULL_HOUSE = 6000000;
public static final int FOUR_OF_A_KIND = 7000000;
public static final int STRAIGHT_FLUSH = 8000000;
public static boolean isOnepair(Card[] cards)
{
if (cards.length != 5)
return false;
if (isFourOfAKind(cards) || isFullHouse(cards) || isThreeOfAKind(cards) || isTwopairs(cards)) return false;
sortByFace(cards);
boolean flag1 = cards[0].face() == cards[1].face();
boolean flag2 = cards[1].face() == cards[2].face();
boolean flag3 = cards[2].face() == cards[3].face();
boolean flag4 = cards[3].face() == cards[4].face();
return (flag1 || flag2 || flag3 || flag4);
}
public static boolean isTwoPairs(Card[] cards)
{
if (cards.length != 5)
return false;
if (isFourOfAKind(cards) || isFullHouse(cards) || isThreeOfAKind(cards))
return false;
sortByFace(cards);
boolean flag1 = cards[0].face() == cards[1].face() && cards[2].face() == cards[3].face();
boolean flag2 = cards[0].face() == cards[1].face() && cards[3].face() == cards[4].face();
boolean flag3 = cards[1].face() == cards[2].face() && cards[3].face() == cards[4].face();
return (flag1 || flag2 || flag3);
}
public static boolean isThreeOfAKind(Card[] cards)
{
if (cards.length != 5)
return false;
if (isFourOfAKind(cards) || isFullHouse(cards))
return false;
sortByFace(cards);
boolean flag1 = cards[0].face() == cards[1].face() && cards[1].face() == cards[2].face();
boolean flag2 = cards[1].face() == cards[2].face() && cards[2].face() == cards[3].face();
boolean flag3 = cards[2].face() == cards[3].face() && cards[3].face() == cards[4].face();
return (flag1 || flag2 || flag3);
}
public static boolean isStraight(Card[] cards)
{
if(cards.length != 5)
return false;
sortByFace(cards);
if (cards[4].face() == 14)
{
boolean flag1 = cards[0].face() == 2 && cards[1].face() == 3 && cards[2].face() == 4 && cards[3].face() == 5;
boolean flag2 = cards[0].face() == 10 && cards[1].face() == 11 && cards[2].face() == 12 && cards[3].face() == 13;
return (flag1 || flag2);
}
else
{
int testface = cards[0].face() + 1;
for (int i = 1; i < 5; i++)
{
if (cards[i].face() != testface)
return false;
testface++;
}
return true;
}
}
public static boolean isFlush(Card[] cards)
{
if (cards.length != 5)
return false;
sortBySuit(cards);
return (cards[0].suit() == cards[4].suit());
}
public static boolean isFullHouse(Card[] cards)
{
if (cards.length != 5)
return false;
sortByFace(cards);
boolean flag1 = cards[0].face() == cards[1].face() && cards[1].face() == cards[2].face() && cards[3].face() == cards[4].face();
boolean flag2 = cards[0].face() == cards[1].face() && cards[2].face() == cards[3].face() && cards[3].face() == cards[4].face();
return (flag1 || flag2);
}
public static boolean isFourOfAKind(Card[] cards)
{
if(cards.length != 5)
return false;
sortByFace(cards);
boolean flag1 = cards[0].face() == cards[1].face() && cards[1].face() == cards[2].face() && cards[2].face() == cards[3].face();
boolean flag2 = cards[1].face() == cards[2].face() && cards[2].face() == cards[3].face() && cards[3].face() == cards[4].face();
return (flag1 || flag2);
}
public static int getValueAtOnePair(Card[] cards)
{
int value = 0;
sortByFace(cards);
if (cards[0].face() == cards[1].face())
{
value = 14 * 14 * 14 * cards[0].face() + +cards[2].face() + 14 * cards[3].face() + 14 * 14 * cards[4].face();
}
else if (cards[1].face() == cards[2].face())
{
value = 14 * 14 * 14 * cards[1].face() + +cards[0].face() + 14 * cards[3].face() + 14 * 14 * cards[4].face();
}
else if (cards[2].face() == cards[3].face())
{
value = 14 * 14 * 14 * cards[2].face() + +cards[0].face() + 14 * cards[1].face() + 14 * 14 * cards[4].face();
}
else
{
value = 14 * 14 * 14 * cards[3].face() + +cards[0].face() + 14 * cards[1].face() + 14 * 14 * cards[2].face();
}
return value + ONE_PAIR;
}
public static int getValueAtTwoPairs(Card[] cards)
{
int value = 0;
sortByFace(cards);
if (cards[0].face() == cards[1].face() && cards[2].face() == cards[3].face())
{
value = 14 * 14 * cards[2].face() + 14 * cards[0].face() + cards[4].face();
}
else if (cards[0].face() == cards[1].face() && cards[3].face() == cards[4].face())
{
value = 14 * 14 * cards[3].face() + 14 * cards[0].face() + cards[2].face();
}
else
{
value = 14 * 14 * cards[3].face() + 14 * cards[1].face() + cards[0].face();
}
return TWO_PAIRS + value;
}
public static int valueAtHighCard(Card[] cards)
{
int value = 0;
sortByFace(cards);
value = cards[0].face() + 14 * cards[1].face() + 14 * 14 * cards[2].face() + 14 * 14 * 14 * cards[3].face() + 14 * 14 * 14 * 14 * cards[4].face();
return value;
}
public static int getValueInHand(Card[] cards)
{
if (isFlush(cards) && isStraight(cards))
{
return valueAtHighCard(cards) + STRAIGHT_FLUSH;
}
else if(isFourOfAKind(cards))
{
sortByFace(cards);
return cards[2].face() + FOUR_OF_A_KIND;
}
else if(isFullHouse(cards))
{
sortByFace(cards);
return cards[2].face() + FULL_HOUSE;
}
else if(isFlush(cards))
{
return valueAtHighCard(cards) + FLUSH;
}
else if (isStraight(cards))
{
return valueAtHighCard(cards) + STRAIGHT;
}
else if (isThreeOfAKind(cards))
{
sortByFace(cards);
return cards[2].face() + THREE_OF_A_KIND;
}
else if(isTwoPairs(cards))
{
return getValueAtTwoPairs(cards);
}
else if (isOnePair(cards))
{
return getValueAtOnePair(cards);
}
else
{
return valueAtHighCard(cards);
}
}
public static void sortByFace(Card[] cards)
{
for(int i = 0; i < cards.length; i++)
{
int minPos = i;
for(int j = i + 1; j < cards.length; j++)
{
if (cards[j].face() < cards[minPos].face())
{
minPos = j;
}
}
Card temp = cards[i];
cards[i] = cards[minPos];
cards[minPos] = temp;
}
}
public static void sortBySuit(Card[] cards)
{
for(int i = 0; i < cards.length; i++)
{
int minPos = i;
for (int j = i + 1; j < cards.length; j++)
{
if (cards[j].suit() < cards[minPos].suit())
{
minPos = j;
}
}
Card temp = cards[i];
cards[i] = cards[minPos];
cards[minPos] = temp;
}
}
}
When I compile it,i get these errors
location: class Card
play.java:167: error: cannot find symbol
else if (cards[0].face() == cards[1].face() && cards[3].face() == cards[4].face())
^
symbol: method face()
location: class Card
100 errors
play.java:17: error: cannot find symbol
if (isFourOfAKind(cards) || isFullHouse(cards) || isThreeOfAKind(cards) || isTwopairs(cards)) return false;
^
symbol: method isTwopairs(Card[])
please fix these errors and update it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started