// CMPU-101-51, Spring 2007
// Asmt 7
// Solutions

// Import java.util package to make using the Arrays class easier.
import java.util.*;

// ---------------------------
//   The YahtzeeHand class
// ---------------------------

class YahtzeeHand {
  
  // ----------------------------------
  //  object-oriented data structure
  // ----------------------------------
  
  private int [] dice = new int[5];
  private int numRollsLeft;
  
  // ----------------------------------
  //  constructor 
  // ----------------------------------
  
  YahtzeeHand() {
    // System.out.println("This YahtzeeHand object brought"
    //                      + " to you by CMPU-245!");
    this.numRollsLeft = 3;
    this.rollEm();
  }
 
  // ----------------------------------
  //  object-oriented methods
  // ----------------------------------
  
  //  rollEm (with String input)
  // ----------------------------
  
  YahtzeeHand rollEm(String rollOrNo) {
    if (this.numRollsLeft <= 0) {
      System.out.println("Hey!  No more rolls left!");
    }
    else {
      for (int i=0; i<5; i++) {
        if (rollOrNo.charAt(i) == 'r') {
          this.dice[i] = (int)(6*Math.random() + 1);
        }
      }
      this.numRollsLeft -= 1;
    }
    return this;
  }
  
  //  rollEm (with no input)
  // ----------------------------
  
  YahtzeeHand rollEm() {
    return this.rollEm("rrrrr");
  }

  //  toString
  // ----------------------------

  public String toString() {
    return "YahtzeeHand:  " + this.numRollsLeft
      + " roll(s) left.  Dice: " + Arrays.toString(this.dice);    
  }
 
  //  score
  // ----------------------------
  int score(int category) {
    int skore = 0;
    for (int i=0; i<5; i++) {
      if (this.dice[i] == category)
        skore += category;
    }
    return skore;                     
  }
  
  
  // --------------------------
  //   stuff added for Asmt 9
  // --------------------------
  
  //  getDie
  // --------------------------------
  //  report the value of the indicated die
  
  int getDie(int indy) {
    return dice[indy];
  }
  
}
