Part 2 The question in this part of the assignment will be g
Solution
import java.util.Random;
public class Gambling {
static Random rn = new Random();
static int diceRoll()
{
int n1 = rn.nextInt(6) + 1;
int n2 = rn.nextInt(6) + 1;
return n1+n2;
}
static boolean canPlay(double balance, double bet)
{
return balance >= bet;
}
static int secondStage(int point)
{
int d;
while(true)
{
d = diceRoll();
if (d == point || d == 7)
{
System.out.println(d);
break;
}
System.out.print(d+\",\");
}
return d;
}
static double passLineBet(double balance, double bet)
{
if (canPlay(balance, bet))
{
int d = diceRoll();
boolean win = true;
if (d == 7 || d == 11)
{
System.out.println(\"A \" + d + \" has been rolled. You win!\");
}
else
{
if (d == 2 || d == 3 || d == 12)
{
System.out.println(\"A \" + d + \" has been rolled. You lose!\");
win = false;
}
else
{
System.out.println(\"A \" + d + \" has been rolled. Roll again!\");
d = secondStage(d);
if (d == 7)
{
System.out.println(\"A \" + d + \" has been rolled. You lose!\");
win = false;
}
else
{
System.out.println(\"A \" + d + \" has been rolled. You win!\");
}
}
}
if (win)
return (balance + bet);
else
return (balance - bet);
}
else
System.out.println(\"Balance is insufficient to place the bet.\");
return balance;
}
public static void main(String[] args)
{
double money = 0;
double bet = 0;
if (args.length == 2)
{
try
{
money = Double.parseDouble(args[0]);
bet = Double.parseDouble(args[1]);
}
catch(Exception e)
{
System.out.println(\"Please run program properly. with argument money bet\");
return;
}
}
else
{
System.out.println(\"Please run program properly. with argument money bet\");
return;
}
money = passLineBet(money, bet);
System.out.println(\"You now have: $\" + money);
}
}


