Java programming assignment help

    Date: 03/03/09 (Computer Geeks)    Keywords: programming, java, web

    Hello, I'm looking for some help with a Java programming assignment.

    The assignment is to create a program in which the user can enter the number of dice they wish to roll and a score. The program is supposed to calculate the probability of the score occurring when their dice have been rolled 100,000 times.

    I am unsure of how to create multiple dice. We've been looking at programs in which you roll one or two dice and then do something with the outcome. How would I go about making it possible to add up the scores of many dice (the user's choice of # of dice, to be exact)? I've formed a primitive Scanner for this but don't know what to add.


    This is all within the class "DiceTester". I have a class "SimpleDice" set up to randomly select a number 1-6 when a die is rolled.

         Scanner scanDie = new Scanner(System.in); // first scanner
     System.out.println("Enter number of dice");
     int n = scanDie.readInt(); // this is where user enters # of dice
      if (n < 0) // if user enters # less than 0
       System.out.println("Error: Number must be 0 or greater."); // there will be an error
    
    
        Scanner scanScore = new Scanner(System.in); // second scanner
        SimpleDice d = new SimpleDice();
     System.out.println("Enter score");
     int m = scanScore.readInt(); // this is where user enters score
     if (m < 0) // if user enters score less than 0
       System.out.println("Error: Score must be 0 or greater"); // there will be an error
        
        int tossCount = 100000; // this is the total # of tosses (designated by assignemnt)
        int scoreCt = m; // this is saying that the # the user entered (m) is now the score count
        int tossResult;
        
        for(int j = 0; j < tossCount; j++){ // for loop used to add up tosses
          tossResult = d.throwDice();
          
          if(tossResult == m) scoreCt++;}
        System.out.println("Success Rate: " + ((double)scoreCt)/tossCount); // this divides the #of times m occurred by the #of times the dice were rolled
    
    



    Any help (even a link to a website that might have useful information) would be greatly appreciated. Thanks for taking the time to look at this.

    Source: http://community.livejournal.com/computergeeks/1245562.html

« When BMW designs a computer... || VIrtualization software »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home