• 08-20-2009, 01:51 AM
JoyMe
public class Twodice{
public static int NUM_GAMES = 10000;

public static void main(String[] args) {
int numWins = 0;
int numLosses = 0;

int x = (int)(Math.random()*6) + 1;
int y = (int)(Math.random()*6) + 1;

System.out.println("The roll of first Dice is " + x);
System.out.println("The roll of Second Dice is " + y);

int roll = (x + y);

System.out.println("The sum of two dice is " + (roll));

int point = (4 & 5 & 6 & 8 & 9 & 10);

for (int i = 1; i<=10000; i++)
if (roll == 7 || roll == 11) {
System.out.println("You win!");
numWins = numWins +1;
} else if (roll==2 || roll==3 || roll==12) {
System.out.println("You Lose!");
numLosses = numLosses + 1;
} else {
System.out.println("Roll Dice again!!!");
int thePoint = roll;
do {
x = (int)(Math.random()*6) + 1;
y = (int)(Math.random()*6) + 1;

roll = (x + y);
if (roll == thePoint)
numWins++;
else if(roll == 7)
numLoses++;
} while (roll != 7 || roll != thePoint);
}
}

System.out.println("In the simulation, we won " + numWins +
" times and lost " + numLosses + " times, ");
System.out.println("for a probability of " +
(double)(numWins)/(double)(numWins + numLosses));
}
}

//------------------------------------------------------------------------------------------
//A player rolls two dice. Each die has six faces. These faces contain one, two, three,
//four, five and six spots, respectively. After the dice have come to rest, the sum of
//the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw,
//the player wins. If the sum is 2, 3 or 12 on the first throw (called “craps”), the player
//loses. If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, that sum becomes the player’s
//“point.” To win, you must continue rolling the dice until you “make your point” (i.e., roll
//your point value). The player loses by rolling a 7 before making the point.
-------------------------------------------------------------------------------------------

Hope it is correct. i find it errors in System.out.println and also how would i make it into a JApplet? Makes my head spinning sir.
• 08-20-2009, 02:10 AM
Fubarable
Without seeing your attempt at a solution, we have no idea of where you're making a mistake, so please post your code so that we may better help you.

When posting code, also please use code tags to make it readable (see FAQ and my signature below). Oh, and welcome to the forum.
• 08-20-2009, 02:13 AM
JoyMe
i will post it here sir
• 08-20-2009, 02:58 AM
Fubarable
Good. We will be on the lookout for it. Best of luck.
• 08-20-2009, 04:16 AM
Eranga
Quote:

Originally Posted by JoyMe
i will post it here sir

Actually this waht you've do in very first post lol. ;)
• 08-20-2009, 12:46 PM
JoyMe
Hello sir i will not yet finish this question. I find it very difficult sir.
• 08-20-2009, 01:09 PM
Fubarable
Well you still have our hopes and prayers for a successful attempt. Good luck.
• 08-20-2009, 01:14 PM
JoyMe
Thank you sir.
• 08-21-2009, 04:29 AM
Eranga
Quote:

Originally Posted by JoyMe
Hello sir i will not yet finish this question. I find it very difficult sir.

At the minute just forget about the applet stuff, correct all the errors in this code.

Can you post the complete error here to see?