/******************************************************************************
* name: Donna Gabai
* netID: dgabai
* precept: P99
*
* Description:
* Maintains two Queues: one with flushes one with fullhouses
* Output number of flushes followed by first 5 flushes.
* Output number of full houses followed by first five full houses.
* If fewer than 5 hands in a queue, print all.
*
* Dependencies: Queue, PokerHand, StdIn, StdOut
*/
public class PokerHandCount {
public static void main(String[] args) {
// maintain 2 queues
Queue<PokerHand> flushes = new Queue<PokerHand>();
Queue<PokerHand> fullHouses = new Queue<PokerHand>();
// 2 counters
int flushCount = 0;
int fullHouseCount = 0;
while (!StdIn.isEmpty()) {
// call PokerHand constructor to read in next hand from StdIn
PokerHand ph = new PokerHand();
if (ph.flush()) {
flushes.enqueue(ph);
flushCount++;
}
else if (ph.fullHouse()) {
fullHouses.enqueue(ph);
fullHouseCount++;
}
}
// output
StdOut.println(" Flushes: " + flushCount);
// first five only or whole queue if fewer than five
int counter = 0;
for (PokerHand ph : flushes) {
StdOut.println(" " + ph);
counter++;
// break out of loop if we found 5
if (counter == 5) break;
}
StdOut.println("Full houses: " + fullHouseCount);
// reset counter
counter = 0;
// first five only
for (PokerHand ph : fullHouses) {
StdOut.println(" " + ph);
counter++;
// break out of loop if we found 5
if (counter == 5) break;
}
}
}