Advertisement
milen_vm

FullHouse

Sep 1st, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. /*
  2.  * In most Poker games, the "full house" hand is defined as three cards of the same face + two cards of the same face,
  3.  * other than the first, regardless of the card's suits. The cards faces are
  4.  * "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and "A". The card suits are "♣", "♦", "♥" and "♠".
  5.  * Write a program to generate and print all full houses and print their number.
  6.  * */
  7.  
  8.  
  9. public class _03_FullHouse {
  10.  
  11.     public static void main(String[] args) {
  12.         String[] cards = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
  13.         String[] colors = {"♠", "♥", "♦", "♣"};
  14.         int countFullHouse = 0;
  15.         for (int i = 0; i < cards.length; i++) {        //gives a card
  16.             for (int f = 0; f < 4; f++) {           //gives one of four combinations
  17.                 String[] fullHouse = new String[5]; //array for the FullHouses
  18.                 switch (f) {
  19.                 case 0:
  20.                     fullHouse[0] = cards[i] + colors[0];    //add every card to the array
  21.                     fullHouse[1] = cards[i] + colors[1];
  22.                     fullHouse[2] = cards[i] + colors[2];                   
  23.                     break;
  24.                 case 1:
  25.                     fullHouse[0] = cards[i] + colors[0];
  26.                     fullHouse[1] = cards[i] + colors[1];
  27.                     fullHouse[2] = cards[i] + colors[3];                   
  28.                     break;
  29.                 case 2:
  30.                     fullHouse[0] = cards[i] + colors[0];
  31.                     fullHouse[1] = cards[i] + colors[3];
  32.                     fullHouse[2] = cards[i] + colors[2];                   
  33.                     break;
  34.                 case 3:
  35.                     fullHouse[0] = cards[i] + colors[3];
  36.                     fullHouse[1] = cards[i] + colors[1];
  37.                     fullHouse[2] = cards[i] + colors[2];                   
  38.                     break;
  39.                 }      
  40.                 for (int j = 0; j < cards.length; j++) {    //gives a card for the next couple
  41.                     if (j == i) {
  42.                                                                                     continue;       //skips a card if is equal to the first
  43.                     }
  44.                         for (int k = 0; k < colors.length; k++) {   //gives color to the card
  45.                             fullHouse[3] = cards[j] + colors[k];    //adding to array
  46.                             for (int p = k + 1; p < colors.length; p++) {   //gives next color to the same card
  47.                                 fullHouse[4] = cards[j] + colors[p];    //adding to array
  48.                                 System.out.print("(");
  49.                                 for (String str : fullHouse) {  //printing fullHouse array
  50.                                     System.out.print(str);
  51.                                 }
  52.                                 System.out.println(")");
  53.                                 ++countFullHouse;   //increasing the counter
  54.                             }
  55.                         }          
  56.                 }
  57.             }                                                                                                  
  58.         }          
  59.         System.out.println(countFullHouse + " full houses");       //printing the counter
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement