In this program(Java) I'm trying to make a dice roller. How do I make it so it rolls a bunch of times and adds the rolls?
Posted
by
Mac
on Stack Overflow
See other posts from Stack Overflow
or by Mac
Published on 2011-01-13T20:49:01Z
Indexed on
2011/01/13
20:53 UTC
Read the original article
Hit count: 215
import java.util.Random;
public class dice
{
private int times;
private int roll;
private int side;
Random roller = new Random();
public void setTimes(int sides)
{
times = sides;
}
public void setSides(int die)
{
side = die;
}
public int getRoll() //this is where the "rolling" happens
{
int total = 0;
int c = 0;
while (c <= times)
{
c = c + 1;
int rol = 0;
roll = roller.nextInt(side) + 1;
rol = rol + roll;
total = rol;
}
return total;
}
}
If you need the GUIWindow and the main, just ask
© Stack Overflow or respective owner