Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Nov 27th, 2005, 9:33 PM   #11
robrosas
Newbie
 
robrosas's Avatar
 
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0 robrosas is an unknown quantity at this point
Here's the code...

This is in a PairOfDice class
public class PairOfDice{
   int first_dice;
   int second_dice;
   int sides=6;
    public PairOfDice(){
    first_dice=0;
    second_dice=0;
    }
    

   


public void roll(){
    first_dice=(int) (Math.random()*sides) + 1;
    second_dice=(int) (Math.random()*sides) + 1;
}


}

And this is in a BoxCars class

  public class BoxCars {
    
    
  public static void main (String[] args){
      int counter=0;
     PairOfDice GameDices= new PairOfDice();
     for(int i=0;i<1000;i++){
        GameDices.roll();
        if((GameDices.first_dice==6)&&(GameDices.second_dice==6)){
        counter++;
        }
      
     }
     System.out.println("The result of cars is :"+counter);   
  }
    
}


Check out is that if what you need.
__________________
From P.R. to the World!! RoBeRt
robrosas is offline   Reply With Quote
Old Nov 27th, 2005, 9:43 PM   #12
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 597
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Please people learn to be a little more organized with your code. It really is a lot easier to read if you indent certain things instead of left aligning everything
crawforddavid2006 is offline   Reply With Quote
Old Nov 28th, 2005, 5:41 PM   #13
robrosas
Newbie
 
robrosas's Avatar
 
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0 robrosas is an unknown quantity at this point
Cool

Quote:
Originally Posted by crawforddavid2006
Please people learn to be a little more organized with your code. It really is a lot easier to read if you indent certain things instead of left aligning everything
Sorry for the gramatical issue Just a code on the fly!!! :eek:
__________________
From P.R. to the World!! RoBeRt
robrosas is offline   Reply With Quote
Old Nov 29th, 2005, 8:51 AM   #14
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
the way the problem is written like "with two Die objects" ...it seems like there should be a class called Die as well. Your code looks pretty good though.

JD
JDStud6 is offline   Reply With Quote
Reply

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:38 PM.

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