Here is the source code that I used when I talked about the assignment. (Don't forget that it's not due until Wednesday, June 14th now!)
import PairOfDice;Here is the source code that I used when talking about references:public class testDice
{
public static void main(String[] args)
{
int value;
// declares a reference do a PairOfDice object
PairOfDice myDice;
// instantiates a PairOfDice object
myDice = new PairOfDice();
// calls the roll method to randomly choose face values
// for the two dice
// similar to the physical act of rolling the two dice
myDice.roll();
// calls the getFaceValue method to find out the face of ONE
// of the two dice
// similar to the physical act of looking at one of the two dice
value = myDice.getFaceValue(myDice.DIE_1);
// calls the getFaceValue method to find out the face of the
// other of the two dice
// similar to the physical act of looking at the other of the
// two dice.
value = myDice.getFaceValue(myDice.DIE_2);
}
}
// primitive data and assignment
int a;
int b;
a = 7;
b = 30;
b = a;
if (b == a)
System.out.println("a and b are equal");
// objects
Coin coin1;
Coin coin2;// the following line is an error because coin1 doesn't
// point to (refer to) a valid object. It currently
// has the value of the null reference
coin1.flip();
coin1 = new Coin();
coin2 = new Coin();
// this prints out "coin1 and coin2 are different objects"
if (coin1 == coin2)
System.out.println("coin1 and coin2 are the same object");
else
System.out.println("coin1 and coin2 are different objects");
coin1 = coin2;// this prints out "coin1 and coin2 are the same object"
if (coin1 == coin2)
System.out.println("coin1 and coin2 are the same object");
else
System.out.println("coin1 and coin2 are different objects");
String playAgain;
playAgain = "y";// the condition is false for the same reason as above
if (playAgain == "y")
System.out.println("playAgain and \"y\" are the same object");
else
System.out.println("playAgain and \"y\" are different objects");