Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Add an instance variable of type Safe to the class Room. This instance variable should be initialised in the constructor of Room, and an appropriate query should be defined to get it.

public class PairOfDice {

    public int die1 = 3;   // Number showing on the first die.
    public int die2 = 4;   // Number showing on the second die.

    public void roll() {
            // Roll the dice by setting each of the dice to be
            // a random number between 1 and 6.
         die1 = (int)(Math.random()*6) + 1;
         die2 = (int)(Math.random()*6) + 1;
    }
    
} // end class PairOfDice
Source by math.hws.edu #
 
PREVIOUS NEXT
Tagged: #Add #instance #variable #type #Safe #class #This #instance #variable #initialised #constructor #query #defined
ADD COMMENT
Topic
Name
3+9 =