Question

public class play { public static final int ONE_PAIR = 1000000; public static final int TWO_PAIRS...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//errors are cleared

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;
}
}
}

//create cards.java


public class Card {

   public int suit() {
      
       return 0;
   }

   public int face() {
      
       return 0;
   }

}

//Since, There is no information about Cards.java, Adding only default methods.

Add a comment
Know the answer?
Add Answer to:
public class play { public static final int ONE_PAIR = 1000000; public static final int TWO_PAIRS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • need help with code it won't compile. import java.util.ArrayList; /** * Counts the ranks of cards...

    need help with code it won't compile. import java.util.ArrayList; /** * Counts the ranks of cards in a hand. * * @author (your name) * @version (a version number or a date) */ public class CountRank { // instance variables - replace the example below with your own private int rankCount[]; private Hand hand; private int count; /** * Constructor for objects of class CountRank */ public CountRank(Hand h) { // initialise instance variables hand = h; rankCount = new...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...

    package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...

  • import java.util.Arrays; public class lab {    public static void main(String args[])    {    int...

    import java.util.Arrays; public class lab {    public static void main(String args[])    {    int arr[] = {10, 7, 8, 9, 1, 5,6,7};    int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};    int arr3[] = {1, 3, 5, 3, 2, 6, 20};    quicksort(arr,0,arr.length-1);    quicksort(arr2,0,arr2.length-1);    quicksort(arr3,0,arr3.length-1);    System.out.println(Arrays.toString(arr));    System.out.println(Arrays.toString(arr2));    System.out.println(Arrays.toString(arr3));       }    private static int partition(int[] items,int low, int high)    {    int i=0;    int j=0;...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • public class FirstLastNameEvent { public final static int ppg = 35; public final static int cutoff...

    public class FirstLastNameEvent { public final static int ppg = 35; public final static int cutoff = 50; private String eventNumber; private int guestNumber; private int price; public void setEventNumber(String eventNumber) { this.eventNumber = eventNumber; } public void setGuestNumber(int guestNumber) { this.guestNumber = guestNumber * ppg; } public String getEventNumber() { return eventNumber; } public int getGuestNumber() { return guestNumber; } public int getPrice() { return price; } } Using Assignment #3’s code:(the code above) Modify the ‘public static void...

  • In the class GraphAlgorithm, insert java code for the method prim public class MyGraph { public...

    In the class GraphAlgorithm, insert java code for the method prim public class MyGraph { public static final int MAXSIZE = 100; public static final double BIGM = 10000000; public MyGraph(int size) { n = size; nodeStart = new Edge[MAXSIZE]; for (int i=0; i<n; i++) { nodeStart[i] = null; } } public int getSize() { return n; } public double getCost(int i, int j) { double value = BIGM; Edge e = nodeStart[i]; while (e !=null) { if (e.dest ==...

  • Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {...

    Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {         int[] array = {7, 1, 3, 2, 42, 76, 9};         insertionSort(array);     }     public static int[] insertionSort(int[] input) {         int temp;         for (int i = 1; i < input.length; i++) {             for (int j = i; j > 0; j--) {                 if (input[j] < input[j - 1]) {                     temp = input[j];                     input[j] = input[j - 1];                     input[j - 1] = temp;                 }             }             display(input, i);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT