I get a syntax error for calling the constructor `PairOfDice()' in main. What's wrong here?
(This isn't C++, but I believe the reasoning is the same--that's why I'm unloading this question on the C++ board.)
Code:
public class MiniMC3 {
public static void main( String[] args ) {
PairOfDice theDice = new PairOfDice(); // Error Error Error
int rollCount = 0;
do {
theDice.roll();
rollCount++;
} while( theDice.getDie1() + theDice.getDie2() != 2 );
System.out.println("You got snake eyes! It took " + rollCount
+ " tries.");
} // End main()
/** Monte-Carlo simulation.
*
* Simulates rolling two dice until they
* add to `sum'.
*
* Precondition: Total lies in range [2, 12]
* Postcondition: Returns number of trials needed to
* achieve `total'.
*
* @param total Target total of two dice
* @return Number of trials to achieve total.
*/
public class PairOfDice {
private int die1;
private int die2;
public PairOfDice() {
roll();
}
public void roll() {
// Roll the dice
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
}
// Getter methods for variables `val1' and `val2'
// (which are declared `private' here).
public int getDie1() {
return die1;
}
public int getDie2() {
return die2;
}
// Setter methods for variables `val1' and `val2'.
public void setDie1( int die ) {
die1 = die;
}
public void setDie2( int die ) {
die2 = die;
}
} // End class PairOfDice()
} // End class MiniMC3