This section of code is where I am testing the algorithm to catch a winning hand i.e. two pair, flush, straight, etc... It is able to find everything except a full house following an XXYYY pattern and two pairs. I'm not getting any errors and doesn't seem to be reaching the part of the code where it searches for that full house and two pair. How should I change the code to find it?
package chapter7Project; import java.util.ArrayList; public class test { /** * @param args */ public static void main(String[] args) { ArrayList<String> hand = new ArrayList<String>(); //hand I will use for testing for two pair hand.add("13 Spades"); //change the card values here for finding out other combos (1-13 or ace-king) hand.add("1 Diamonds"); hand.add("2 Spades"); hand.add("2 Spades"); hand.add("13 Spades"); ArrayList<Integer> hCard = new ArrayList<Integer>();//ArrayLists for testing for combos ArrayList<String> hSuit = new ArrayList<String>(); //separate cards and suits for(String i : hand) { i = i.trim();//removes spaces at the beginning int j = 0; boolean done = false; String acard = ""; while(!done) { if(i.substring(j, j+1).equalsIgnoreCase(" "))//changes face cards to numbers { if(acard.equalsIgnoreCase("Jack")) { acard = "11"; } if(acard.equalsIgnoreCase("Queen")) { acard = "12"; } if(acard.equalsIgnoreCase("King")) { acard = "13"; } if(acard.equalsIgnoreCase("Ace")) { acard = "1"; } hCard.add(Integer.parseInt(acard.trim())); done = true; } acard += i.substring(j, j+1); j++; } } //gets each suit for(String i : hand) { i = i.trim(); int j = i.length()-1; String asuit = ""; boolean done = false; while(!i.substring(j, j+1).equalsIgnoreCase(" ")) { j--; } j++; while(!done) { asuit += i.substring(j, j+1); if(i.substring(j, j+1).equalsIgnoreCase(" ")||j==i.length()-1) { hSuit.add(asuit.trim()); done = true; } j++; } } //puts the cards in numerical order int j = 0; ArrayList<Integer> greatest = new ArrayList<Integer>();//contains the cards placed in numerical order ArrayList<String> boobs = new ArrayList<String>(); boobs.add(""); boobs.add(""); boobs.add(""); boobs.add(""); boobs.add(""); //fills the arraylists with 5 slots greatest.add(0); greatest.add(0); greatest.add(0); greatest.add(0); greatest.add(0); int i = 0; //algorithm for putting the cards in numerical order //by adding 1 to 'j' for each card its greater than //sorts from least to greatest while(greatest.contains(0)) { for(int a : hCard) { j = 0; int index = i; for(int c : hCard)//checks if one card is bigger than another { if(a > c) j++; if ( a == c)//if the cards are the same, it looks for the next available slot { int b = greatest.indexOf(a); if(b == 4) { j = 3; break; } else if (b==3) { if(greatest.get(4) == 0){ j = 4; } else { j = 2; } break; } else if (b==2) { if(greatest.get(3) == 0) { j = 3; } else if(a == greatest.get(3)) { j = 4; } else { j = 1; } break; } else if(b==1) { if(greatest.get(2) == 0) { j = 2; } else if(a == greatest.get(2)) { j=3; if(a == greatest.get(3)) { j=4; } } else { j = 1; } break; } else if(b==0) { if(a == greatest.get(1)) { j = 2; if( a == greatest.get(2)) j=3; } else { j = 1; } break; } } } greatest.set(j,a);//puts the card in the slot where it's supposed to be boobs.set(j, hSuit.get(index));//gets the suit where the card is and puts it in the same index as the card put in greatest i++; } hCard.removeAll(hCard);//removes all cards from hcCArd hCard.addAll(greatest);//puts the sorted cards in hCard hSuit.removeAll(hSuit);//does the same for the suits hSuit.addAll(boobs); System.out.println(hCard); System.out.println(hSuit); } boolean pair = false; boolean twoPair = false; boolean threeOfAKind = false; boolean straight = false; boolean flush = false; boolean fullHouse = false; boolean fourOfAKind = false; boolean straightFlush = false; boolean royalFlush = false; //checks for royal flush if(hCard.contains(1)&&hCard.contains(10)&&hCard.contains(11)&&hCard.contains(12)&&hCard.contains(13))//checks for 10-ace { int check = 0; String k = hSuit.get(0); for(String a : hSuit)//checks if the suits are all the same { if(a.equalsIgnoreCase(k)) { check++; } if(check==5) { royalFlush = true; } } } //checks for pair, 2 pair, 3 of a kind, full house, and four for of a kind int l = 0; while( l <= hCard.size()-1)//finds the first matching pair { if(hCard.get(l) != hCard.get(l+1)) l++; else { break; } } if(hCard.get(l) == hCard.get(l+1)&&l<hCard.size())//if there's a pair, it goes through here to search for other possibilities { System.out.println(l); if(l <= 1) { l++; System.out.println(l); if(hCard.get(l) == hCard.get(l+1))//three of a kind if true { if(l < 2) { l++; System.out.println(l); if(hCard.get(l) != hCard.get(l+1))// checks for a full house { if(l < 3) { l++; System.out.println(l); if(hCard.get(l) == hCard.get(l+1))//if three of a kind then pair, XXXYY, then full house is true { fullHouse = true; } } } if(hCard.get(l) == hCard.get(l+1))//checks for four of a kind { fourOfAKind = true; } else//else it's a three of a kind { threeOfAKind = true; } } else// if 'l' is too big then three of a kind is true { threeOfAKind = true; } } else if(l < 1)//looks for two pair and full house patter, yyxxx { l++; System.out.println(l); //section where i need help if(hCard.get(l) != hCard.get(l-1)&&hCard.get(l) == hCard.get(l+1)) //checks if the next card is equal to the last and is equal to the next { if(l < 2) { l++; System.out.println(l); if(hCard.get(l) == hCard.get(l+1)&&hCard.get(l+1)==hCard.get(l+2))//checks for a three of a kind { fullHouse = true; } } else if(fullHouse == false) { twoPair = true; } } } } else { if(hCard.get(l) != hCard.get(l-1)&&hCard.get(l) == hCard.get(l+1))//looks specifically for a two pair { if(l < 2) { l++; System.out.println(l); if(hCard.get(l) == hCard.get(l+1)&&hCard.get(l+1)!=hCard.get(l+2))//looks if the two pair is seperated or together { twoPair = true; } if(hCard.get(l) != hCard.get(l+1)&&hCard.get(l+1)==hCard.get(l+2)) { twoPair = true; } //down to here } } } if(twoPair == false && fullHouse == false && threeOfAKind == false && fourOfAKind == false)//if everything else is false, pair is at least true pair = true; } //looks for a flush int check = 0; String k = hSuit.get(0); for(String a : hSuit) { if(a.equalsIgnoreCase(k)) { check++; } } if(check==5) { flush = true; } //looks for a straight if(hCard.get(1) == (hCard.get(0)+1) && hCard.get(2)== (hCard.get(1)+1) && hCard.get(3) == hCard.get(2)+1 && hCard.get(4) == hCard.get(3)+1) { straight = true; } else if(hCard.contains(1) && hCard.contains(10) && hCard.contains(11) && hCard.contains(12) && hCard.contains(13)) { straight = true; } //if straight and flush are true, then you have a straight flush if(straight == true && flush == true && royalFlush == false) { straightFlush = true; straight = false; flush = false; } //looks if anything is one if(royalFlush == true) { System.out.println("HOLY FUCK BALLS, ROYAL FLUSH!!"); } if(pair == true) { System.out.println("pair"); } if(twoPair == true) { System.out.println("two pair"); } if(threeOfAKind == true) { System.out.println("three of a kind"); } if(fullHouse == true) { System.out.println("full house"); } if(fourOfAKind == true) { System.out.println("four of a kind"); } if(flush == true) { System.out.println("flush"); } if(straight == true) { System.out.println("straight"); } if(straightFlush == true) { System.out.println("straight flush"); } } }