so i'm trying to make a program where once the die is rolled, then a picture prints...
my random generator is working properly, but its my print() method thats not.. once i've rolled the die, it gives a random number, but once i do the print method, the topValue turns into a negative which ruins my print() method.. HELP please, i'm not sure what im doing wrong??????
once i run my main method which is this...
public class DieTest
{
public static void main(String[] args)
{
Die die1=new Die();
die1.roll();
die1.print(); //topValue turns into negative =( .. so it doesnt follow what it was in the roll() method
}
}
import java.util.Random;
public class Die
{
private int topValue;
private int getTopValue()
{
return topValue;
}
public void roll()
{
Random rndm1= new Random();
for(topValue = 1; topValue >= 1; topValue++);
int topValue = rndm1.nextInt(6);
}
public void print()
{
if(topValue == 1)
System.out.print( "+-------+\n| |\n| o |\n| |\n+-------+\n" );
else if(topValue == 2)
System.out.print( "+-------+\n| o |\n| |\n| o |\n+-------+\n" );
else if(topValue == 3)
System.out.print( "+-------+\n| o |\n| o |\n| o |\n+-------+\n" );
else if(topValue == 4)
System.out.print( "+-------+\n| o o |\n| |\n| o o |\n+-------+\n" );
else if(topValue == 5)
System.out.print( "+-------+\n| o o |\n| o |\n| o o |\n+-------+\n" );
else{
System.out.print(topValue +"+-------+\n| o o |\n| o o |\n| o o |\n+-------+\n" );
}
}
}