Results 1 to 9 of 9

Thread: Roll The dice

  1. #1
    Subhanrukh is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default 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.

  2. #2
    Subhanrukh is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    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.

  3. #3
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    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
    Java Code:
    BufferedReader input = new BufferedReader(InputStreamReader(System.in));
    String inputFromUser = input.readLine();
    it would be better if you figured a lot of this out for yourself, but we can point you in the right direction.

  4. #4
    Subhanrukh is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    yah, i don't want the answer. because i learned that last time that you don't learn anything with plain out answers.

  5. #5
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    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

  6. #6
    Subhanrukh is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    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.

  7. #7
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    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.

  8. #8
    Subhanrukh is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    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

  9. #9
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    Okay so you made a class to handle all of your rolling.
    As for the prompt, where do you want it to prompt them? and what exactly do you want it to ask?

Similar Threads

  1. Need help with java rapid roll game
    By blunderblitz in forum New To Java
    Replies: 1
    Last Post: 03-02-2010, 01:36 PM
  2. Help with a dice game.
    By hero in forum AWT / Swing
    Replies: 14
    Last Post: 07-26-2009, 12:50 PM
  3. Roll dice class with three dices
    By nube07 in forum New To Java
    Replies: 4
    Last Post: 07-14-2008, 02:37 AM
  4. Roll 2-Dice "Pig" Game Help
    By King8654 in forum AWT / Swing
    Replies: 7
    Last Post: 04-07-2008, 07:58 PM
  5. Help debugging a dice game
    By Windoze in forum New To Java
    Replies: 7
    Last Post: 11-22-2007, 02:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •