![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2008
Posts: 8
Rep Power: 0
![]() |
Ten sided die simulator.
Hello everyone! This is the first time I have really tried to program, so I'd like to apologize in advance if the code I'm about to present is god-awful. Here's the basic idea, A certain # of 10 sided dice (w/ values 1-10) will be rolled, if the resulting number on any die is above a certain threshold it will be recorded and if it above another threshold then it will be recorded, and "rolled" again.
For example If I instructed it to roll 5 dice with a threshold of 8 and a repeat of 10 and the results were: 1,3,7,10,8 the program would tally the 2 successes and "roll" the ten again resulting in a 9, there would then be 3 successes and the program would end and output the tally to a text area. So far I have an almost functional program, the current issue is that it will only allow the generation of one # at a time. If more then one "roll" is requested, or it hits the again threshold when rolling 1 die it will run forever. Just so you know I'm implementing it into a GUI, but for simplicity's sake I'll leave that code out. And if it matters I'm working in the Net Beans IDE. java Syntax (Toggle Plain Text)
Thank you in advance you your help, any advice is much appreciated. |
|
|
|
|
|
#2 | ||
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Ten sided die simulator.
Quote:
Also, I think you want your num1 to equal Math.random()%10, the modulus operator. I'm not sure the exact syntax Java uses though. Quote:
Also, you can clean your code up a bit by removing the redundant statements. Only increment a variable in one conditional statement, not in every conditional statement. You'll find it helps with troubleshooting to limit where a variable is modified. |
||
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2008
Posts: 8
Rep Power: 0
![]() |
Re: Ten sided die simulator.
from what I've seen though an array has to be a fixed length, thereby it cannot be made flexible enough to accept any # of "rolls", as defined by a variable.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Re: Ten sided die simulator.
If thats the case then Check out ArrayLists and or Vectors, these are used as arrays but are classes, best of all you do not have to specify a size for them. You can add and delete entries as you please.
Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 203
Rep Power: 2
![]() |
Re: Ten sided die simulator.
Use ArrayList. Their use is simple. At the top, import java.util.*;
and an ArrayList works like an array, except that it has methods to help you. Google Java Sun ArrayList and read their method descriptions. For example, the add method will allow you to continue adding to a list in order to make it larger dynamically. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2008
Posts: 8
Rep Power: 0
![]() |
Re: Ten sided die simulator.
Awesome sauce, I'll look into it more after finals week is over, and I'll get back to you guys with my progress.
Thank you all again, Cribbageman |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cache simulator..PLZ HELP | Natsoumi_Maya | C | 0 | Apr 25th, 2008 3:41 AM |
| Network Simulator design | renato | Software Design and Algorithms | 2 | Dec 11th, 2007 10:54 PM |
| GPS Simulator alogorithm | fisherking | C++ | 10 | Apr 28th, 2006 3:39 AM |
| Starship Combat Simulator | ChiHappens | Existing Project Development | 7 | Feb 14th, 2006 4:59 PM |