Hi All,
I am needing some assistance on how I can grab the values for the number of die that come up as 1, 2, 3, 4, 5 or 6. I have the count variables holding the count for each one that fits the "if statement". But I can't use the count variables(onesCnt, twosCnt and etc)within the public static void main part of the code as it is saying "non static variable onesCnt cannot be referenced from a static context". Can someone tell me how I can grab the values so I can print out the output on the screen for the count variables? I tried to create a get method to use the return method to grab the count variables but that didn't work either :(
public class Die
{
public static final int MAXROLLS = 100;
public int[] dieRollCnt;
private int onesCnt;
public int twosCnt;
public int threesCnt;
public int foursCnt;
public int fivesCnt;
public int sixesCnt;
public static void main(String[] args)
{
//System.out.println("This concludes the example" + onesCnt);
}
public void die(int[] dot)
{
System.out.println("We will roll the die 100 times and store the input for the variables");
int dieRollCount[] = new int[MAXROLLS];
int oneCount = 0;
int twoCount = 0;
int threeCount = 0;
int fourCount = 0;
int fiveCount = 0;
int sixCount = 0;
for(int i=0; i < dieRollCount.length; i++)
{
//System.out.println("Random Number ["+ (i+1) + "] : " + (int)(Math.random()*6));
dieRollCount[i] = (int) (Math.random()*6) + 1;
//System.out.println("Die Roll [" + (i+1) + "] + dieRollCount[i]");
System.out.println("Die Roll Number ["+ (i+1) + " + is ] = " + dieRollCount[i]);
if(dieRollCount[i] == 1 )
{
onesCnt += oneCount++;
}
else if(dieRollCount[i] == 2)
{
twosCnt += twoCount++;
}
else if(dieRollCount[i] == 3)
{
threesCnt += threeCount++;
}
else if(dieRollCount[i] == 4)
{
foursCnt += fourCount++;
}
else if(dieRollCount[i] == 5)
{
fivesCnt += fiveCount++;
}
else if(dieRollCount[i] == 6)
{
sixesCnt += sixCount++;
}
else
System.out.println("Please contact the developer as the code is not"
+ "functioning correctly");
}
}
}