Hey guys! I'm doing another school project, bleh ._.

The method I need help on is called isFlush. It's a boolean that needs to determine whether the hand (subDeck) is a flush or not.

A flush contains five cards with the same suit. I want to know how to just check for suit and disregard rank. This is what I have so far below, the method I need help is the final one before main.


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Deck;

/**
 *
 * @author Josh
 */
public 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 = 0; rank <= 12; rank++) {
                    cards[index] = new Card (suit, rank);
                    index++; 
                }
            }
        }
// prints the whole deck, card by card
        public static void printDeck (Deck deck) {
            for (int i = 0; i < deck.cards.length; i++) {
                Card.printCard(deck.cards[i]);
            }
    }
// generates a random integer between low and high
            public static int randInt (int low, int high) {
                double x = Math.random() * (high - low + 1);
                return (int) x + low;
            }
            public void swapCards (int i, int n) {
                Card card1 = cards[i];
                cards[i] = cards[n];
                cards[n] = card1;
            }

        public void shuffleDeck () {
            for (int i=0; i<cards.length; i++) {
                int random = randInt (i, cards.length-1);
                swapCards (i, random);
            }
    }
        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 pokerHand4 (Deck deck) {
            int lowCard = 0;
            int highCard = 4;
            for (int i = 1; i < 5; i++) {
               Deck hand = subDeck (deck, lowCard, highCard);
               Deck.printDeck (hand);
               lowCard += 4;
               highCard += 4;
            }
        }

        public static boolean isFlush (Deck deck) {
            int count = 0;
            // traverses the deck, will be flush if all cards are the same
            for (int i = 0; i < deck.cards.length-1; i++) {
                if (deck.cards[i] == deck.cards[i+1]) {
                    count++;
                    if (count == 5) {
                        return true;
                    }
                }
            }
            return false;
    }

        public static void main (String[] args) {
            // create new deck
            Deck newDeck = new Deck ();
            // shuffles deck
            newDeck.shuffleDeck();
            // tests pokerHand4
            pokerHand4 (newDeck);
        }
}

Where do you specify the suits? Or am I going blind in these early hours

edit: ah I see, 0-3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.