Date: Tue, 01 Oct 2002 22:26 From: Mark Jacobson To: 810-061-01@uni.edu, 810-061-02@uni.edu Subject: What are the PIVs for Die class? On Tue, 1 Oct 2002, Jonathon J. Java Junior wrote: > Hello Mark, > I have finished the java class, but have one problem. The getRoll > function seems like it should hold a number variable for each die > rolled. Since at the end of yahtzee.java die1.getRoll() and the rest of > the die are checked with getRoll. Wouldn't all of these variables have > to be held some where to check the statement? Maybe another function in > Yahtzee.java? > J.J.J.J. Hi 061 students, I have had two questions this evening like this one about the Die and Yahtzee program. The Die class has all of the Private Instance Variables (PIVs) in it you need, except for the generator for the random integers that was overlooked. generator.nextValue() is of course needed, to simulate rolling a die and getting a 1, 2, 3, 4, 5 or 6. Guess what? In the Die.java file that you download there is an int variable called currentRoll. Guess what that variable is for. It is for storing or remembering what the current value of the die is. If the last time you rolled it, it came up showing a 4, then the currentRol PIV stores the value 4. private int currentRoll; // This PIV remembers what the current // face value of the die is, and you use // this PIV when an accessor function // needs to report the die value... private Text currentRollText; // This 2nd PIV is used to DISPLAY the digit // 1, 2, 3, 4, 5 or 6 for the player to see. There is a PIV in the original file Die.java that you downloaded called: currentRoll The die1 or die2 or whichever instance of the Die class remembers its own value in the int variable currentRoll and the accessor function -------- getRoll() tells you or the Yahtzee client what the value of the most recent dice roll is. The PIV currentRoll is PRIVATE, but the PUBLIC accessor function getRoll() is used to access the information. ------ Every instance of the class Die has its own private instance variables. Thus die1, die2 and die3 and so on each is an instance of the Die class. Each of the 5 instances of the Die class has its own FilledRect, FramedRect, Text and currentRoll variables. The currentRoll int is for remembering the state of the die as regards its value. --- ----- Mark