I am working on coding a program to roll dice. I am very new to java still as I am taking classes for schooling. I am using multiple classes in different packages for this program, what I am trying to figure out is, in one class, for my package pairOfDice, I have created objects in a class pairOfDice, die1 and die2. Now I have another package rollDice, adn my goal is to use the pairOfDice class to roll two die and display the rolls. what I am struggling with is how to exactly do that. When I am rolling the die my results display as if I am only rolling one die. I have made adjustments to display two die every roll, although feel as if I am not doing it in a more proficient sort of way.
package die;
import java.util.Scanner;
/**
*
* @author <a href= "mailto:adavi125@my.chemeketa.edu" >Aaron Davis</a>
*/
public class RollDice
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
PairOfDice dice = new PairOfDice();
// get amount of rolls from user
System.out.print("How many rolls do you want? ");
int numRolls = scan.nextInt();
int diceOne, diceTwo;
int boxCar, snakeEyes;
int j = 0, k = 0;
// rolls the dice the requested amount of times
for (int i = 0; i < numRolls; i++)
{
// first die to roll
diceOne = dice.roll();
// second die to roll
diceTwo = dice.roll();
// display rolled dice
System.out.println(diceOne + " " + diceTwo + "\n");
// store and display pairs of 1 rolls
if (diceOne == 1 && diceTwo == 1)
{
snakeEyes = ++j;
System.out.println("\nThe number of snake eyes you have is: "
+ snakeEyes + "\n");
}
// store and display pairs of 6 rolls
if (diceOne == 6 && diceTwo == 6)
{
boxCar = ++k;
System.out.println("\nThe number of box cars you have is: "
+ boxCar + "\n");
}
}
}
}
******************************************************************************
/*
the integers diceOne and diceTwo are my workarounds, my other package contains
public class PairOfDice extends Die
{
Die die1, die2;
public PairOfDice()
{
die1 = new Die();
die2 = new Die();
}
public PairOfDice(int face)
{
die1 = new Die(face);
die2 = new Die(face);
}
}
*/
******************************************************************************
// i am un-clear how to make "PairOfDice dice = new PairOfDice();" come out as two die