Results 1 to 4 of 4
  1. #1
    waparson is offline Member
    Join Date
    Jul 2008
    Posts
    21
    Rep Power
    0

    Default Help with dice game...student seeking advice

    Hi, im new here. taking a beginner class in java. this second program is giving me a time...

    the rules of the program are in the text attachment. Im having trouble figuring out what i need in a loop. and if i need nested loops.

    Also can i nest a for loop inside a do while loop.

    This one is giving me a hard time guys, please help....

    also yes this is a homework problem, not trying to get someone to give me the answer or do it for me, just need some direction on this one....

    thanks,
    Allan
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    Yes you can nest one type of loop within another.
    Give the program a start. If you don't know what to code at a particular point, write some comments on what you'd like to do there. For example:
    // Here I roll a die and get a random value from 1 to 6.
    or
    // Get the number of games to be played

    Layout the structure of the game, post it with your questions and someone will help.

  3. #3
    waparson is offline Member
    Join Date
    Jul 2008
    Posts
    21
    Rep Power
    0

    Default

    while (userGuess != sum)
    {
    for (countRolls = 1; countRolls <=3; countRolls++)
    {
    //create a Random class object.
    Random randomNumbers = new Random();

    //Get two random numbers.
    dice1 = randomNumbers.nextInt(6);
    dice2 = randomNumbers.nextInt(6);

    //Sum the two die numbers
    sum = (dice1 + dice2)

    //output the number of each die with asteriks
    System.out.println("Die 1 Die 2");
    System.out.println("-----------------");


    ok, i believe i have the most of it. One thing thats getting me is how to output a picture of the asteriks for whatever random number is generated for each die. I know im gonna have to do an if/else statement for this..


    any help on how to do this would greatly be appreciated....
    Last edited by waparson; 07-21-2008 at 05:07 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    picture of the asteriks
    You could use substring for this.
    String asters = "*****************";
    String twoAster = asters.substring(0,2);

    You'll want to create the Random object outside of the method. Otherwise you'll always get the same numbers, unless you seed it from the CPU clock, for example.

Similar Threads

  1. Roll 2-Dice "Pig" Game Help
    By King8654 in forum AWT / Swing
    Replies: 7
    Last Post: 04-07-2008, 06:58 PM
  2. Student Help
    By mattwaab in forum Java Applets
    Replies: 0
    Last Post: 02-08-2008, 05:31 PM
  3. please help a student
    By jvasilj1 in forum New To Java
    Replies: 0
    Last Post: 02-01-2008, 01:11 AM
  4. Help debugging a dice game
    By Windoze in forum New To Java
    Replies: 7
    Last Post: 11-22-2007, 01:01 AM
  5. help debugging a dice game
    By Windoze in forum Advanced Java
    Replies: 0
    Last Post: 11-16-2007, 10:28 PM

Posting Permissions

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