I think my issue is with the PairOfDice class because I need to only use an object containing both dice values in the EyesHaveIt class. I keep getting errors like: PairOfDice.java:16: error: class, interface, or enum expected public int getDie1() ^
PairOfDice.java:19: error: class, interface, or enum expected } ^
PairOfDice.java:21: error: class, interface, or enum expected public int getDie2() ^
PairOfDice.java:24: error: class, interface, or enum expected } ^
EyesHaveIt.java:44: error: cannot find symbol int die1 = dieOne.getDieOneValue(); ^ symbol: method getDieOneValue() location: variable dieOne of type PairOfDice EyesHaveIt.java:45: error: cannot find symbol
Here is my attempt at trying to fix it. Thanks!
Here's my Die Class:
import java.util.Random;
public class Die
{
public static Random generator = new Random();
public int roll ()
{
return generator.nextInt(6) + 1; // Randome # dice between 1-6
}
}
\\Here's my PairOfDice class:
public class PairOfDice
{
private int die1Value;
private int die2Value;
public PairOfDice()
{
Die die1 = new Die();
Die die2 = new Die();
die1Value = die1;
die2Value = die2;
}
}
public int getDie1()
{
return die1;
}
public int getDie2()
{
return die2;
}
}
Here is the EyesHaveIt class where I'm trying to use that code:
import java.util.Scanner;
public class EyesHaveIt
{
Scanner kb = new Scanner(System.in);
private int turnScore;
private int computerTotalScore;
private int playerTotalScore;
private int computerTurnNumber;
private int playerTurnNumber;
public int roundPoints;
private String userName;
public void init(String name)
{
userName = name;
}
public void playGame()
{
computerTurn();
}
public void computerTurn()
{
turnScore = 0;
System.out.println("Computer Turn: ");
while (turnScore < 20)
{
rollTheDice();
}
}
public void rollTheDice()
{
PairOfDice dieOne = new PairOfDice();
PairOfDice dieTwo = new PairOfDice();
int die1 = dieOne.getDieOneValue();
int die2 = dieTwo.getDieOneValue();
System.out.println("Rolled: " + die1 + " and " + die2);
}
This class will be an abstraction of a physical pair of standard six-sided dice. Only one object of this class will be created by the EyesHaveIt object and used throughout the game by both players. You should consider this object to be a pair of dice. When a player rolls during a turn, that player is rolling the PairOfDice object. Players never roll a Die object directly. The client of the PairOfDice class will roll the PairOfDice object, get the values of each die in the pair, etc. This class should have exactly two attributes: two objects of the class, Die. This is the only class that uses the Die class.