Date: 03/03/09 (Computer Geeks) Keywords: programming, java, web Hello, I'm looking for some help with a Java programming assignment. 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
|