Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 9th, 2008, 8:38 PM   #1
cribbageman2500
Newbie
 
Join Date: Apr 2008
Posts: 8
Rep Power: 0 cribbageman2500 is on a distinguished road
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)
  1. import java.util.*;
  2. import javax.swing.*;
  3.  
  4. public class D10sim extends javax.swing.JFrame {
  5.  
  6.  
  7. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  8. int gen, tally, num1;
  9. double dice = Double.parseDouble(jTextField1.getText());
  10. double thresh = Double.parseDouble(jTextField2.getText());
  11. double again = Double.parseDouble(jTextField3.getText());
  12. gen = 0;
  13. tally = 0;
  14. {num1 = (int) ((Math.random() * 10) + 1);
  15. while (gen<dice)
  16. {if (num1>=again)
  17. {dice ++;
  18. tally ++;
  19. gen ++;}
  20. else
  21. if (num1>=thresh)
  22. {tally ++;
  23. gen ++;}
  24. else
  25. if (num1<thresh)
  26. {gen ++;}
  27. jTextArea1.setText(String.valueOf(tally));
  28. }
  29. }
  30.  
  31. }

Thank you in advance you your help, any advice is much appreciated.
cribbageman2500 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC