Write a method called isFlush that takes an array of Cards as a parameter and that returns true if the hand contains a flush, and false otherwise. A flush is a poker hand that contains five or more cards of the same suit.
Code:
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 void main(String[] args) {
for (; suit <= 3; suit++) {
for (int rank = 1; rank <= 13; rank++) {
deck[index] = new Card (suit, rank);
index++;
}
}
boolean flush = isFlush();
if (flush = true){
System.out.println("Congratulations! You have a flush!");
}
else {
System.out.println("Sorry, you do not have a flush.");
}
}
public boolean isFlush(Card[] x) {
int count = 0;
for(index = 0; index < x.length; index++){
boolean comp = compareCard(x[index], x[index + 1]);
if (comp = true){
count++;
}
}
if (count >= 5){
return true;
}
else{
return false;
}
}
public boolean compareCard(Card c1, Card c2){
if (c1.suit != c2.suit){
return false;
}
return true;
}
}