title: Yahtzee Application class
body: <p>I'm a bit of a noob when it comes to programming, and I could really use help with an assignment I've been working on. I'm trying to get a yahtzee program working with this expected output (the rolled dice are random)</p>
  
  <pre><code>Round 1 
  Roll 1: 
  5 6 5 5 2 
  Which die value do you want to keep? 
  5 
  Roll 2: 
  5 6 5 5 3 
  Which die value do you want to keep? 
  5 
  Roll 3: 
  5 1 5 5 5 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 0 points 
  5s: 0 points 
  These values are automatically output 
  to the console when you call the 
  showDice method in the GUI class.  Page 6 of 9
  6s: 0 points 
  5 
  Round 1 complete. 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 0 points 
  5s: 20 points 
  6s: 0 points 
  
  Round 2 
  Roll 1: 
  1 2 4 4 3 
  Which die value do you want to keep? 
  4 
  Roll 2: 
  3 4 4 4 6 
  Which die value do you want to keep? 
  4 
  Roll 3: 
  4 4 4 4 4 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 0 points 
  5s: 20 points 
  6s: 0 points 
  4 
  Round 2 complete. 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  
  Round 3 
  Roll 1: 
  5 1 4 1 6 
  Which die value do you want to keep? 
  5 
  Roll 2: 
  5 2 4 1 3 
  Which die value do you want to keep? 
  5 
  Roll 3: 
  5 6 3 1 3 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points  Page 7 of 9
  5 
  There is already a score for location 5. Which location would you like to 
  record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  4 
  There is already a score for location 4. Which location would you like to 
  record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 0 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  3 
  Round 3 complete. 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  
  Round 4 
  Roll 1: 
  1 3 2 3 1 
  Which die value do you want to keep? 
  1 
  Roll 2: 
  1 2 2 5 1 
  Which die value do you want to keep? 
  2 
  Roll 3: 
  2 2 2 2 1 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 0 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  2 
  Round 4 complete. 
  Scores: 
  1s: 0 points 
  2s: 8 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  
  The player can choose to 
  keep the value 1 after the 
  first roll, but choose to 
  keep value 2 after the 
  second roll. 
  If the player attempts to enter a score in 
  a location that already has a score, they 
  are told the location already has a score 
  and are asked again to choose a 
  location. They will continue to be 
  asked until they enter an empty 
  location.  Page 8 of 9
  Round 5 
  Roll 1: 
  4 5 1 5 6 
  Which die value do you want to keep? 
  6 
  Roll 2: 
  1 2 5 4 6 
  Which die value do you want to keep? 
  6 
  Roll 3: 
  6 1 1 1 6 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 8 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 0 points 
  6 
  Round 5 complete. 
  Scores: 
  1s: 0 points 
  2s: 8 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 12 points 
  
  Round 6 
  Roll 1: 
  1 6 4 3 2 
  Which die value do you want to keep? 
  1 
  Roll 2: 
  1 6 6 1 2 
  Which die value do you want to keep? 
  1 
  Roll 3: 
  1 5 5 1 6 
  Which location would you like to record this round? 
  Scores: 
  1s: 0 points 
  2s: 8 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 12 points 
  1 
  Round 6 complete. 
  Scores: 
  1s: 2 points 
  2s: 8 points 
  3s: 6 points 
  4s: 20 points 
  5s: 20 points 
  6s: 12 points 
  </code></pre>
  
  <p>Game over! Your total score is 68</p>
  
  <p>This is the code I have so far</p>
  
  <pre><code>  package proj5;
      import java.util.Scanner;
  
      public class Project5App {
  
          public static void main (String[] args)
          {
              Scanner sc = new Scanner(System.in);
              GUI diceTable = new GUI();
              DiceArray dice = new DiceArray(5);
              int[] scoreCard = new int[]{0,0,0,0,0,0};
              int count = 1;
  
              for(int j = 1; j &lt; 7; j++)// j: rounds
              {
                  System.out.println("Round " + j);
                  for (int i = 1; i &lt;= 3; i++)// i: the rolls 
                  {
                      if(i &lt; 3)
                      {
                          System.out.println("Roll " + i + ":");
                          dice.roll();
                          diceTable.showDice(dice);
                          System.out.println("Which die value do you want to keep?");
                          int keep = sc.nextInt();
                          dice.keep(keep);
                      }
  
                      if (i == 3)
                      {   
                          System.out.println("Roll " + i + ":");
                          dice.roll();
                          diceTable.showDice(dice);
                          System.out.println("Which location would you like to record this round?\nScores:");
                          for(int k = 0; k &lt; 6; k++)//k: score card location
                          {
                              if (scoreCard[k] &gt; 0)
                                  System.out.println("There is already a score for location " );
                                  System.out.println(count + "s: " + scoreCard[k] + " points");
                                  count++;
                          }
                          count = 1;
                          int location = sc.nextInt();
                          int sum = dice.calculateTotal(location);
                          System.out.println(location);
  
                          System.out.println("Round " + j + " complete.");
                          dice.reset();   
                      }
                  }
              }
          }   
      }
  </code></pre>
  
  <p>I'm not too sure on how to get my scorecard to display twice in the round without making 2 loops and I don't know how to get the added dice to display in the scorecard at the end of the round. I just can't figure this one out on my own. Can anyone offer any insight?</p>
  
  <p>Edit: Heres the entire DiceArray class My expected output and what I want it to do is written above.</p>
  
  <pre><code>    package proj5;
  /**
   * &lt;p&gt;Title: Project 5&lt;/p&gt;
   *
   * &lt;p&gt;Description: Creates an array of dice that rolls, keeps and displays the values of each die. &lt;/p&gt;
   *
   * @author 
   */
  
  public class DiceArray 
  {
      //instance variables
      private int[] dice;
      private boolean[] diceToRoll;
  
      /**
       * Name: Parameterized Constructor &lt;/P&gt;
       * Description: Receives the number of dice, and instantiates both instances variables. &lt;/p&gt;
       * @param numDice the number of dice to be used
       */
      public DiceArray(int numDice)
      {
          dice = new int[numDice];
          diceToRoll = new boolean[numDice];
  
          for(int i = 0; i &lt; dice.length; i++)
          {   
              dice[i] = -1;
              diceToRoll[i] = true;
          }   
      }
  
      /**
       * Name: toString method &lt;/P&gt;
       * Description: Create and return a string with the values of the dice, and whether or not they are kept. &lt;/p&gt;
       * @return a String with the values of the die and whether or not they are true or false
       */
      public String toString()
      {
          String output = "";
          for(int i = 0; i &lt; dice.length; i++)
          {
              output += dice[i] + " ";
          }
          output += "\n";
          for(int i = 0; i &lt; dice.length; i++)
          {   
              if (diceToRoll[i] == true)
                  output += "T" + " ";
              else
                  output += "F" + " ";
          }
  
          return output;
      }
  
      /**
       * Name: roll method &lt;/P&gt;
       * Description: Rolls dice based on which ones are set to 'true'. &lt;/p&gt;
       */
      public void roll()
      {
          for (int i = 0; i &lt; dice.length; i++)
          {   
              if (diceToRoll[i] == true)
                  dice[i] = (int)(Math.random() * 6 + 1);
          }   
      }
  
      /**
       * Name: getDice method &lt;/P&gt;
       * Description: Return the reference of the array dice. &lt;/p&gt;
       * @return the value of the reference of the array.
       */
      public int[] getDice()
      {
          return dice;
      }
  
      /**
       * Name: reset method &lt;/P&gt;
       * Description: Sets all the diceToRoll values to true, allowing them all to be 
       * rolled the next time the roll method is called. &lt;/p&gt;
       */
      public void reset()
      {
          for (int i = 0; i &lt; dice.length; i++)
              diceToRoll[i] = true;
      }
  
      /**
       * Name: keep method &lt;/P&gt;
       * Description: Will accept an int that indicates which of the dice value that should be kept. &lt;/p&gt;
       * @param diceVal the value to be compared to the dice values
       */
      public void keep(int diceVal)
      {
          for(int i = 0; i &lt; dice.length; i++)
          {
              if(dice[i] == diceVal)
                  diceToRoll[i] = false;
              else
                  diceToRoll[i] = true;
          }
      }
  
      /**
       * Name: calculateTotal method &lt;/P&gt;
       * Description: Will accept an int indicating which of the values to calculate a total for. &lt;/p&gt;
       * @param val the value of the dice values to be added together
       * @return an int of the sum of the values
       */ 
      public int calculateTotal(int val)
      {
          int sum = 0;
  
          for(int i = 0; i &lt; dice.length; i++)
          {
              if (dice[i] == val)
                  sum = sum + val;
          }
  
          return sum;
      }
  
  
  }
  </code></pre>