Results 1 to 9 of 9
- 02-11-2011, 09:33 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
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.
-
I think the first place to start would be this article: So, You Need to Write a Program but Don't Know How to Start. I know that it has helped me and may help you.
Luck!
- 02-11-2011, 09:51 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
lol from the title it sounds up my alley for sure
- 02-13-2011, 05:32 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
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
- 02-13-2011, 05:56 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
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); }
- 02-13-2011, 09:05 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 70
- Rep Power
- 0
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.
- 02-13-2011, 10:12 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
-
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
-
I need a little direction for a dictionary app
By Alexis in forum AWT / SwingReplies: 5Last Post: 02-11-2011, 07:43 PM -
random direction
By i8java in forum Threads and SynchronizationReplies: 5Last Post: 04-26-2010, 10:37 PM -
Looking for direction...
By ewomack in forum New To JavaReplies: 4Last Post: 09-13-2009, 11:00 PM -
[SOLVED] Need direction...
By hotice1027 in forum New To JavaReplies: 5Last Post: 11-28-2008, 09:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks