Craps is a popular dice game played in casinos Write a progr
Solution
/* CraapsGame: dice game played in casinos */
import java.util.Scanner;
public class CraapsGame
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int dice1;
int dice2;
dice1 = (int)(6.0*Math.random() + 1.0);
dice2 = (int)(6.0*Math.random() + 1.0);
int sum = dice1 + dice2;
System.out.println(\"You rolled \" + dice1 + \" + \" + dice2 + \" = \" + sum);
if (sum == 2 || sum == 3 || sum == 12)
{
System.out.println(\"You lose\ \");
System.exit(1);
}
else if (sum == 7 || sum == 11)
{
System.out.println(\"You win\ \");
System.exit(1);
}
else
{
// point: 4, 5, 6, 8, 9, or 10
int point = sum;
System.out.println(\"Point is \" + point);
while (true)
{
// keep rolling
dice1 = (int)(6.0*Math.random() + 1.0);
dice2 = (int)(6.0*Math.random() + 1.0);
sum = dice1 + dice2;
System.out.println(\"You rolled \" + dice1 + \" + \" + dice2 + \" = \" + sum);
if (sum == point)
{
System.out.println(\"You won\ \");
break; // break out of loop, a win
}
else if (sum == 7)
{
System.out.println(\"You lose\ \");
break; // break out of loop, a loss
}
}
}
}
}
/*
Output:
You rolled 5 + 1 = 6
Point is 6
You rolled 5 + 4 = 9
You rolled 2 + 3 = 5
You rolled 3 + 1 = 4
You rolled 3 + 6 = 9
You rolled 5 + 3 = 8
You rolled 6 + 1 = 7
You lose
You rolled 1 + 4 = 5
Point is 5
You rolled 1 + 3 = 4
You rolled 3 + 6 = 9
You rolled 5 + 1 = 6
You rolled 1 + 2 = 3
You rolled 5 + 3 = 8
You rolled 4 + 2 = 6
You rolled 4 + 4 = 8
You rolled 4 + 5 = 9
You rolled 1 + 5 = 6
You rolled 5 + 4 = 9
You rolled 3 + 2 = 5
You won
*/
