Results 1 to 9 of 9
  1. #1
    misterwebb is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Unhappy Point in the right direction? Dice

    Okay so i have a program i need to make for my class. Dont want anyone to really solve it just need a push in the right direction and hopefully i can do the rest sooo here it goes.

    The program simulates rolling a die with 6 sides. It should ask the user if they would like to continue accumulating the frequency of rolls stored in a data file, if the file exists. If no files exists, then the program creates one and stores the results at the end of the program. Then the program should ask the user the number of times to roll the die. The program should then simulate the rolling of the die and output the data to a dialog box as a table containing column headers of face and frequency. Frequency is the number of times each face was rolled. The program should also save the frequency of roles back to the file as accumulated data. Do not delete the data in the file. Instead the frequency of each face should be an accumulation of rolls from each run of the program. According to the rules of probability, the more times you roll the die, the closer the frequencies should get to being equal. Use error checking to ensure the user types in valid information.

    Any help with this would be much appreciated, new to programming and just reading this makes me want to drop the class haha.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    misterwebb is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    lol from the title it sounds up my alley for sure

  4. #4
    misterwebb is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Okay so now im to the point i know i need to import a java.util.random. and use one integer variable such as num1 = randomNumbers.nextInt(6); But how would i make it execute the number of times the user says to roll the die? Still very confused on this one all the way through

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by misterwebb View Post
    Okay so now im to the point i know i need to import a java.util.random. and use one integer variable such as num1 = randomNumbers.nextInt(6); But how would i make it execute the number of times the user says to roll the die? Still very confused on this one all the way through
    You would get the user input as an int, and then use this int at the top bound of a for loop. In pseudo-code:

    Java Code:
    get input from user and place in int variable rollDiceTimes
    for loop from int i = 0 to i < rollDiceTimes
       roll my dice and do something with the result.
    end for loop

  6. #6
    misterwebb is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    So something like this?

    Java Code:
    system.out.print("How many times do you want to roll the die");
    rollTimes = keyboard.nextInt();
    
    for(int i = 0, i < rollTimes)
    {
      Confused in this part, the actual rolling of the die?
      
      //Write the results to a file
      outputFile.println(dieRoll);
    }

  7. #7
    Adomini is offline Member
    Join Date
    Aug 2010
    Posts
    70
    Rep Power
    0

    Default

    Yes - that is better. Do you see the last part of your code that says:

    outputFile.println(dieRoll); ** dieRoll**

    the middle of your loop, tell the computer what dieRoll is. Know what I mean?

    Your for loop is going through the whole rollTimes - which is good. While the computer is doing that make the number of times you had to go through the whole program to DieRoll.

    I am not an experienced programmer by any means, but I have taken a couple of java classes.

  8. #8
    misterwebb is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Adomini View Post
    Yes - that is better. Do you see the last part of your code that says:

    outputFile.println(dieRoll); ** dieRoll**

    the middle of your loop, tell the computer what dieRoll is. Know what I mean?

    Your for loop is going through the whole rollTimes - which is good. While the computer is doing that make the number of times you had to go through the whole program to DieRoll.

    I am not an experienced programmer by any means, but I have taken a couple of java classes.
    so inside my for loop i should put
    Java Code:
    dieRoll = randomNumbers.nextInt(6);
    
    BUT how would i display the results correctly? it needs to have the number 1 through 6 
    in one column then the frequency in the column beside it.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Don't worry about displaying things from within the for loop as this is only for getting roll results. You'll need an array, and then depending on the roll result in the for loop, increase the corresponding array element by one. So, if the die rolls 3, then increase myArray[3] by one and store it back into the myArray[3] spot. You would also use the same array to store numbers from the file and to write numbers to a file and for display, but all of this later stuff is done after the for loop has concluded.

Similar Threads

  1. I need a little direction for a dictionary app
    By Alexis in forum AWT / Swing
    Replies: 5
    Last Post: 02-11-2011, 07:43 PM
  2. random direction
    By i8java in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-26-2010, 10:37 PM
  3. Looking for direction...
    By ewomack in forum New To Java
    Replies: 4
    Last Post: 09-13-2009, 11:00 PM
  4. [SOLVED] Need direction...
    By hotice1027 in forum New To Java
    Replies: 5
    Last Post: 11-28-2008, 09:03 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
  •