Results 1 to 9 of 9
Thread: Roll The dice
- 04-18-2010, 08:43 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
Roll The dice
This is for a test, if it was a homework i would've found my own way some how the other. But i can't mess around with the test it's due tonight.
The main objective is, Ask the user IF they want to roll the dice, then if they choose to do so, roll the dice, then simulate rolling the dice by generating two random numbers and assigning them to your variable. Display the number rolled for each die -- be sure to use appropriate captions. Compare the two values rolled. If the values of each die match, print an appropriate response. Once the dice have been rolled, prompt the user to roll the dice again. And continued.
- 04-18-2010, 08:47 PM #2
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
public class RollTheDice {
public static void main(String[] args) {
Random generator = new Random();
int die1;
int die2;
int count = 1;
int SnakeEyes = 1;
int Dueces = 1;
int Trips = 1;
int CrazyEight = 1;
int TenAgain = 1;
int BoxCars = 1;
System.out.println ("You rolled snake eyes " + SnakeEyes +
" out of " + count + " rolls.");
System.out.println ("You rolled dueces " + Dueces +
" out of " + count + " rolls.");
System.out.println ("You rolled trips " + Trips +
" out of " + count + " rolls.");
System.out.println ("You rolled crazy eights" + CrazyEight +
" out of " + count + " rolls.");
System.out.println ("You rolled ten again " + TenAgain +
" out of " + count + " rolls.");
System.out.println ("You rolled boxcars " + BoxCars +
" out of " + count + " rolls.");
}
}
I started with that.. I'm still working on it. If any 1 can help i would really really apprecaite it.
- 04-18-2010, 08:59 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
You need to actually use your Random object that you created.
Secondly don't you need to set all your counters to 0 at defualt?
Thirdly you need a way of inputing, i'm assuming this isn't graphical? so in this case you are probably going to want to use
it would be better if you figured a lot of this out for yourself, but we can point you in the right direction.Java Code:BufferedReader input = new BufferedReader(InputStreamReader(System.in)); String inputFromUser = input.readLine();
- 04-18-2010, 09:00 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
yah, i don't want the answer. because i learned that last time that you don't learn anything with plain out answers.
- 04-18-2010, 09:02 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
Oh yeah, uhm you might want to use Scanner instead of BufferedReader, i learned off bufferedreader so that's what i use.
Just note that to use buffered reader you need to import java.io.*; and your main method must throw IOException
- 04-18-2010, 09:03 PM #6
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
i think i'm supposed to use a scanner class.
How would i get the user to be prompted, yes or no for using the software.
- 04-18-2010, 09:06 PM #7
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
well first you would need to print something out to the user so they know what they are expected to enter.
something simple like, System.out.println("Enter \"roll\" to roll the dice");
then use Scanner to get a string from them, i don't know scanners to be honest but i'm hoping you can handle that. then compare the string they entered to roll using the .equals() method for Strings to see if it mathes roll.
- 04-19-2010, 06:56 AM #8
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
OK so i got how i can make it give me the rolling i still can't get how to make it prompt.
public class RollTwoPairs {
public static void main(String[] args) {
PairOfDice firstDice; // Refers to the first pair of dice.
firstDice = new PairOfDice();
PairOfDice secondDice; // Refers to the second pair of dice.
secondDice = new PairOfDice();
int countRolls; // Counts how many times the two pairs of
// dice have been rolled.
int total1; // Total showing on first pair of dice.
int total2; // Total showing on second pair of dice.
countRolls = 0;
do { // Roll the two pairs of dice until totals are the same.
firstDice.roll(); // Roll the first pair of dice.
total1 = firstDice.die1 + firstDice.die2; // Get total.
System.out.println("First pair comes up " + total1);
secondDice.roll(); // Roll the second pair of dice.
total2 = secondDice.die1 + secondDice.die2; // Get total.
System.out.println("Second pair comes up " + total2);
countRolls++; // Count this roll.
System.out.println(); // Blank line.
} while (total1 != total2);
System.out.println("It took " + countRolls
+ " rolls until the totals were the same.");
} // end main()
} // end class RollTwoPairs
- 04-19-2010, 08:39 AM #9
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
Need help with java rapid roll game
By blunderblitz in forum New To JavaReplies: 1Last Post: 03-02-2010, 12:36 PM -
Help with a dice game.
By hero in forum AWT / SwingReplies: 14Last Post: 07-26-2009, 11:50 AM -
Roll dice class with three dices
By nube07 in forum New To JavaReplies: 4Last Post: 07-14-2008, 01:37 AM -
Roll 2-Dice "Pig" Game Help
By King8654 in forum AWT / SwingReplies: 7Last Post: 04-07-2008, 06:58 PM -
Help debugging a dice game
By Windoze in forum New To JavaReplies: 7Last Post: 11-22-2007, 01:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks