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 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
 

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 11:30 PM.

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