Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Java dice roll simulation  (Read 3669 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: July 27, 2008, 09:33:17 AM »

Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. DiceRoll class
  3. *****************
  4. By: HappyFace http://www.engineeringserver.com
  5. Contact: info [@] engineeringserver.com
  6. Version: 27/07/2008
  7. "*****************
  8. Note: Rolling a dices
  9. //----------------------------------------------------------------------*/
  10.  
  11. public class DiceRoll {
  12.  
  13. public static void main(String[] args) {
  14. DiceRoll DR = new DiceRoll();
  15. DR.rollDice(3, 6); // roll 3 dices each with 6 sides.
  16. }
  17. public void rollDice(int roll, int side){
  18. int total = 0;
  19. System.out.println("Rolling the dice " + roll + " times with " + side + " sides");
  20. for (int i = 0; i < roll; i++){
  21. int dice = (int) (1+ Math.random()*side);
  22. System.out.println("Dice(s) rolled: " + dice);
  23. total = total + dice;
  24. }
  25. System.out.println("Total amount rolled: " + total);
  26. }
  27. }
  28.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
jac4593
Junior Member
*

Reputation: 0
Offline Offline
Posts: 2
Referrals: 0

Awards
« Reply #1 on: July 27, 2008, 05:19:07 PM »

Isnt this the same as


Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. // Author List:
  3. //      deAppel <Creator>
  4. //
  5. // Description:
  6. // Rolling a dice.
  7. //
  8. // Environment:
  9. //      This software was developed using Eclipse and Java 1.6
  10. //
  11. // Copyright Information:
  12. //      Copyright (C) 2007      <Institution><None>
  13. // Ark de Appel www.engineeringserver.com
  14. //
  15. //----------------------------------------------------------------------*/
  16.  
  17. public class DiceRoll {
  18.  
  19. public static void main(String[] args) {
  20. DiceRoll DR = new DiceRoll();
  21. DR.rollDice(3, 6); // roll 3 dices each with 6 sides.
  22. }
  23. public void rollDice(int roll, int side){
  24. int total = 0;
  25. System.out.println("Rolling the dice " + roll + " times with " + side + " sides");
  26. for (int i = 0; i < roll; i++){
  27. int dice = (int) (1+ Math.random()*side);
  28. System.out.println("Dice(s) rolled: " + dice);
  29. total = total + dice;
  30. }
  31. System.out.println("Total amount rolled: " + total);
  32. }
  33. }
Created by GeSHI 1.0.7.20


I'm new to Java dft001
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #2 on: July 27, 2008, 05:27:10 PM »

Haha it's ok that you are new into java. We all started somewhere and you come to the right place to learn java.

And yes, i accidentally posted the same thing here twice. I used to post here with the name "deAppel" but changed my username to "HappyFace"
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
jac4593
Junior Member
*

Reputation: 0
Offline Offline
Posts: 2
Referrals: 0

Awards
« Reply #3 on: July 27, 2008, 05:35:14 PM »

Yeah I just checked that out then I saw the same thing again  005

Yeah I've just got "Head First Java" from my uncle, only problem its 600+ Pages :(
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #4 on: July 27, 2008, 05:41:41 PM »

Yeah I just checked that out then I saw the same thing again  005

Yeah I've just got "Head First Java" from my uncle, only problem its 600+ Pages :(

That's a nice bookyou got there indeed, i personally recommend that book for people that just started Java. I also recommend other "head first" books such as


These books are easy to read and easy to understand. If you have a specfic question you can also post it here on the forums so we can help you with it or browse the forum and look if your question hasn't been answered already by someone else  Very nice

« Last Edit: July 27, 2008, 05:43:41 PM by HappyFace » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
lethalboom
Junior Member
*

Reputation: 0
Offline Offline
Posts: 5
Referrals: 0

Awards
« Reply #5 on: July 28, 2008, 11:30:29 AM »

Thanks for showing us that, very helpful Happy (Well, I doubt I'll ever use it, but you know, now I'm learning java it might just come in handy wink)
Logged
nofear
Junior Member
*

Reputation: 0
Offline Offline
Posts: 1
Referrals: 0

Awards
« Reply #6 on: July 30, 2008, 11:45:13 AM »

Yeah...I don't know about programming...But I am very interested to Learn Java...What I should do?
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #7 on: July 30, 2008, 11:50:31 AM »

Yeah...I don't know about programming...But I am very interested to Learn Java...What I should do?

I suggest to read a book and read this topic: http://www.engineeringser...m/forum/empty-t312.0.html if you need specific help like solving your coding problem just post in the appropiate board and someone will help you out.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here