Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:07:57+00:00 2026-06-03T00:07:57+00:00

I have another exercise I have to do that I really need help with.

  • 0

I have another exercise I have to do that I really need help with. I don’t even know if my isFlush method is working because for seem reason my deck isnt shuffling and dealing a hand and I’m completely stuck. Can someone help me or point me in the right direction or something? Here is the exercise:

Exercise 12.5 The goal of this exercise is to write a program that generates
random poker hands and classifies them, so that we can estimate the probability of
the various poker hands. Don’t worry if you don’t play poker; I’ll tell you everything
you need to know.

a. As a warmup, write a program that uses shuffleDeck and subdeck to generate
and print four random poker hands with five cards each. Did you get anything
good? Here are the possible poker hands, in increasing order of value:
pair: two cards with the same rank
two pair: two pairs of cards with the same rank
three of a kind: three cards with the same rank
straight: five cards with ranks in sequence
flush: five cards with the same suit
full house: three cards with one rank, two cards with another
four of a kind: four cards with the same rank
straight flush: five cards in sequence and with the same suit

b. Write a method called isFlush that takes a Deck as a parameter and returns a
boolean indicating whether the hand contains a flush.

c. Write a method called isThreeKind that takes a hand and returns a boolean
indicating whether the hand contains Three of a Kind.

d. Write a loop that generates a few thousand hands and checks whether they
contain a flush or three of a kind. Estimate the probability of getting one of
those hands.

e. Write methods that test for the other poker hands. Some are easier than others.
You might find it useful to write some general-purpose helper methods that can
be used for more than one test.

f. In some poker games, players get seven cards each, and they form a hand with
the best five of the seven. Modify your program to generate seven-card hands
and recompute the probabilities.

And here is my code:

public class Poker {

    public static void main(String[] args) {
        Deck deck = new Deck ();
        Deck.dealDeck (deck);
    }

}
class Card {

    int suit, rank;
    int index = 0;
    //Card[] deck = new Card [52];

    public Card () {
        this.suit = 0; this.rank = 0;
    }

    public Card (int suit, int rank) {
        this.suit = suit; this.rank = rank;
    }

    public static void printCard (Card c) {
        String[] suits = { "Clubs", "Diamonds", "Hearts", "Spades" };
        String[] ranks = { "narf", "Ace", "2", "3", "4", "5", "6",
        "7", "8", "9", "10", "Jack", "Queen", "King" };
        System.out.println (ranks[c.rank] + " of " + suits[c.suit]);
    }
}

class Deck {

    Card[] cards;


    public Deck (int n) {
        cards = new Card[n];
    }

    public Deck () {
        cards = new Card[52];
        int index = 0;
        for (int suit = 0; suit <= 3; suit++) {
            for (int rank = 1; rank <= 13; rank++) {
                cards[index] = new Card (suit, rank);
                index++;
            }
        }
    }

    public static Deck dealDeck(Deck deck){
        shuffle(deck);
        Deck hand1 = subDeck(deck, 0, 4);
        Deck hand2 = subDeck(deck, 5, 9);
        Deck hand3 = subDeck(deck, 10, 14);
        Deck hand4 = subDeck(deck, 15, 19);
        Deck pack = subDeck(deck, 20, 51);
        return deck;
    }

    public static Deck shuffle(Deck deck){
        for (int i = 0; i < 52; i++){
            int rand = (int)(Math.random()*(i + 1));
            **Deck[] temp = deck[i];
            deck[i] = deck[rand];
            deck[rand] = deck[temp];**
        }
        return deck;
    }

    public static Deck subDeck(Deck deck, int low, int high) {
        Deck sub = new Deck (high-low+1);
        for (int i = 0; i < sub.cards.length; i++) {
            sub.cards[i] = deck.cards[low+i];
        }
        return sub;
    }

    public static void printDeck (Deck hand) {
        for (int i = 0; i < hand.cards.length; i++) {
            Card.printCard (hand.cards[i]);
        }
    }

    public static boolean isFlush(Card[] x, int y) {
        int count = 0;
        for(int index = 0; index < y; index++){
            boolean comp = compareIfFlush(x[index], x[index + 1]);
            if (comp = true){
                count++;
            }
        }
        if (count >= 5){
            System.out.println("Congratulations! You have a flush!");
            return true;
        }
        else{
            System.out.println("Sorry, you do not have a flush.");
            return false;
        }
    }

    public static boolean compareIfFlush(Card c1, Card c2){
        if (c1.suit != c2.suit){
            return false;
        }
        return true;
    }
}

I put in bold the part I’m having trouble with. I get the error: “array required, but exercise125poker.Deck found”. I need a work around for this error because I don’t know how to fix it so I’m stuck. Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:08:00+00:00Added an answer on June 3, 2026 at 12:08 am

    Your Deck type isn’t an array type. It has an array in it, but you can’t use it like one – which is what’s generating your error. Consider this… what if your Deck had two Card[52]s in it? then if you called deck[25] it wouldn’t make any sense. Typically when you’re hiding an array inside an object you’ll want to expose the array with accessor methods like public Card get(int i) to retrieve elements out of an inner array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have another programmer who I'm trying to explain why it is that a
i have another question on getting my XML serialization neat, which i can't seem
I have another question and I can't seem to find anything on Google. What
I have another Richfaces question which may seem rather weird. I am developing a
I have a WCF solution that consists of the following class libraries: Exercise.Services: Contains
I need an help to solve an exercise. #include <stdio.h> #include <stdlib.h> #include <string.h>
I have several models that are related to one another through a HABTM relationship.
FYI. Another practice exercise that I'm stuck on. The problem is to find the
i have another piece for more advanced guys than me ;) I am developing
I have another csv file where I am trying to do a simple word

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.