
October 21st, 2009, 10:37 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 2
Time spent in forums: 1 h 2 m 39 sec
Reputation Power: 0
|
|
|
Die rolling program?
Hey everyone, I'm EXTREMELY new to Java. I've been working on two programs, the first gets and sets random numbers (1-6) and the second grabs the random numbers from the first program, then displays which of the two rolls is higher.
here's the first:
Code:
import java.util.*;
import java.util.Random;
public class Die
{
private int value;
public int getRoll()
{
return value;
}
public void setRoll
(int HIGHEST_DIE_VALUE, int LOWEST_DIE_VALUE )
{
int value = ((int) (Math.random() * 100 ) % 6 + 1);
}
}
the second is:
Code:
public class twoDice2 {
public static void main(String[] args)
{
int FirstRoll;
int SecondRoll;
Die D = new Die();
FirstRoll = D.getRoll();
SecondRoll = D.getRoll();
System.out.println("The first roll: " + FirstRoll );
System.out.println("The second roll: " + SecondRoll );
if( FirstRoll == SecondRoll )
{
System.out.println("The dice are equal");
}
else
if( FirstRoll > SecondRoll )
{
System.out.println("Die one wins");
}
else
if( FirstRoll < SecondRoll )
{
System.out.println("Die two wins");
}
}
They both compiled properly, but only show the rolls as always equal, and always 0.
Please help if you can, thanks!
|