title: Poker Dice Program in Java
body: <p>[Edit: I fixed the two pair and full house mix up, however my final score where there are no pairs and it displays the highest value is not firing at all]</p>
  
  <p>I am working on a project that plays a dice poker game.  I have all of the "scoring" working except when the dice roll two pairs[Edit: two pairs fixed], it says it is a full house. </p>
  
  <p>Here are the instructions: </p>
  
  <blockquote>
    <p>In this lab you will write a Java program that plays the game Poker Dice.  In this game, five dice are rolled and scored as if they were a hand of playing cards.  The game goes through two separate phases.  In the first phase, a "hand" of dice is presented to the player.  The player then selects which dice he wants to keep and which he wants to re-roll.  Once that decision is finished, all of the dice that the player has marked to re-roll are re-rolled and the final "hand" of dice is displayed.  The hand should then be scored according to the rules of Poker Dice (given below) and the result displayed on the screen. </p>
  </blockquote>
  
  <p>Here are the scoring rules: 
  <a href="https://i.stack.imgur.com/AM0HK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AM0HK.png" alt="enter image description here"></a></p>
  
  <p>Here is my code for the scoring method:</p>
  
  <pre><code>private static String getResult(int[] dice) {
      int i = 0;
  
      String results = "";
  
      int endResultsCheck = 0;
  
      int[] count = getCounts(dice);
  
      // Checks for 5 of a kind
      while (i &lt; count.length) {
          if (count[i] == 5) {
              results = "Five of a kind!";
              endResultsCheck = 7;
          }
          i++;
      }
  
      // Checks for four of a kind
      i = 0;
      if (endResultsCheck != 7) {
          while (i &lt; count.length) {
              if (count[i] == 4) {
                  results = "Four of a kind!";
                  endResultsCheck = 6;
              }
              i++;
          }
      }
      if (endResultsCheck &lt; 6) {
          // Checks for full house
          i = 0;
          int check = 0;
          while (i &lt; count.length) {
              if (count[i] == 3) {
                  check++;
              }
              if (count[i] == 2) {
                  check++;
              }
              i++;
          }
          if (check == 2) {
              results = "Full house!";
              endResultsCheck = 5;
          }
      }
      if (endResultsCheck &lt; 5) {
          // Checks for three of a kind
          i = 0;
          while (i &lt; count.length) {
              if (count[i] == 3) {
                  results = "Three of a kind!";
                  endResultsCheck = 4;
              }
              i++;
          }
      }
      if (endResultsCheck &lt; 4) {
          // Checks for two pairs
          i = 0;
          int check = 0;
          while (i &lt; count.length) {
              if (count[i] == 2) {
                  check++;
              }
              i++;
          }
          if (check == 2) {
              results = "Two pairs!";
              endResultsCheck = 3;
          }
      }
      if (endResultsCheck &lt; 3) {
          i = 0;
          while (i &lt; count.length) {
              if (count[i] == 2) {
                  results = "One pair!";
              }
              i++;
          }
          endResultsCheck = 2;
      }
      if (endResultsCheck == 0) {
          i = 0;
          int max = 0;
  
          while (i &lt; dice.length) {
              if (max &lt; dice[i]) {
                  max = dice[i];
              }
              i++;
          }
          results = "Highest number is " + max + "!";
      }
  
      return results;
  
  }
  </code></pre>
  
  <p>When it refers to method <code>getCounts()</code>, it is this code: </p>
  
  <pre><code>private static int[] getCounts(int[] dice) {
      int[] count = new int[10];
      int i = 0;
  
      int one = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 1) {
              one++;
          }
          i++;
      }
      int two = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 2) {
              two++;
          }
          i++;
      }
      int three = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 3) {
              three++;
          }
          i++;
      }
      int four = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 4) {
              four++;
          }
          i++;
      }
      int five = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 5) {
              five++;
          }
          i++;
      }
      int six = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 6) {
              six++;
          }
          i++;
      }
      int seven = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 7) {
              seven++;
          }
          i++;
      }
      int eight = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 8) {
              eight++;
          }
          i++;
      }
      int nine = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 9) {
              nine++;
          }
          i++;
      }
      int ten = 0;
      i = 0;
      while (i &lt; dice.length) {
          if (dice[i] == 10) {
              ten++;
          }
          i++;
      }
  
      count[0] = one;
      count[1] = two;
      count[2] = three;
      count[3] = four;
      count[4] = five;
      count[5] = six;
      count[6] = seven;
      count[7] = eight;
      count[8] = nine;
      count[9] = ten;
  
      return count;
  
  }
  </code></pre>