There is an issue with my Java program. I need to simulate a craps game, but two methods don't seem to be registering in the program. public boolean update() and public void printreport(). They need to represent the number of games played, percentage of games won and lost , current account balance, percentage increase or decrease in account balance since the session began in the ouput. The account balance in my program doesn't seem to be used even though it was inputed in the Dialog box.  Program: import javax.swing.JOptionPane; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.util.Random; public class Craps { double balance, startBalance, bet; int wins, loss, games; boolean win; boolean eligibletoPlay; public enum Status { CONTINUE, WON, LOST }; final static int SNAKE_EYES = 2; final static int TREY = 3; final static int SEVEN = 7; final static int ELEVEN = 11; final static int BOX_CARS = 12; final static double MIN_BALANCE = 100.00; final static double MIN_BET = 1.00; Scanner input; public static void main (String[] args) throws Exception { Craps game = new Craps(); game.AccountData(); game.NewGame(); } public void NewGame() { String answer; input = new Scanner(System.in); while (true) { System.out.print("Do you wish to play another game? "); answer = input.next(); if (answer.toLowerCase().charAt(0) == 'y') { play(); } else if (answer.toLowerCase().charAt(0) == 'n') { printreport(); System.exit(5); } else System.out.println("Please type in either 'y' to play again or 'n' to quit"); } } public boolean play() { int point = 0; int sumOfDice = roll(); Status gameStatus; switch (sumOfDice) { case SEVEN: case ELEVEN: gameStatus = Status.WON; System.out.printf("Player rolls: %d\n", sumOfDice); break; case SNAKE_EYES: case TREY: case BOX_CARS: gameStatus = Status.LOST; System.out.printf("Player rolls: %d\n", sumOfDice); break; default: gameStatus = Status.CONTINUE; point = sumOfDice; System.out.printf("Player rolls: %d\n", point); } while ( gameStatus == Status.CONTINUE ) { sumOfDice = roll(); System.out.printf("Player rolls: %d\n", sumOfDice); if (sumOfDice == point) { gameStatus = Status.WON; } else if (sumOfDice == SEVEN) { gameStatus = Status.LOST; } } if ( gameStatus == Status.WON ) { System.out.printf("Congratulations, You win\n\n", sumOfDice); } else System.out.printf("Sorry, you've lost\n\n", sumOfDice, point); NewGame(); return play(); } public void AccountData() { String response; JOptionPane.showMessageDialog(null, "Hello, and Welcome to the Craps Game;"); while (true) { response = JOptionPane.showInputDialog(null, "Enter your starting account balance ($)"); try { startBalance = Double.parseDouble(response); } catch (NullPointerException e) { JOptionPane.showMessageDialog(null, "Error: The box cannot be empty!"); continue; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Error: You must enter a numeric value in the box!"); continue; } if (startBalance >= MIN_BALANCE) break; System.out.printf("Please enter at least $%5.2f for a starting balance\n", MIN_BALANCE); } balance = startBalance; wins = 0; loss = 0; games = 0; play(); } public boolean update () { games++; if (win) { wins++; balance = balance - bet; } else { loss++; balance = balance - bet; } System.out.printf("Your total account balance is now: %4.2f", balance); if (balance < MIN_BET) { eligibletoPlay = false; System.out.println("Sadly, you are no longer eligible to play"); } return update(); } public void printreport() { if (games > 0) { double changed = balance - startBalance; double percentchanged = (changed/startBalance) * 100; double percentwins = (wins/(double)games) * 100; double percentlosses = (loss/(double)games) * 100; System.out.printf("Of the %d games you have played you have won %d (%4.2f) , lost %d (%4.2f)", games, wins, percentwins, loss, percentlosses); if (changed < 0 ) { System.out.printf("Your balanced has decreased by %4.2f (%-4.2f)\n", changed, percentchanged); System.out.printf("You have no more money left, bye\n"); } else if (changed > 0) { System.out.printf("Your balanced has increased by %4.2f (%4.2f)\n", changed, percentchanged); System.out.printf("Bye, enjoy your winnings"); } } } public static int roll () { int dice1; int dice2; dice1 = 1 + (int)(6.0*Math.random()); dice2 = 1 + (int)(6.0*Math.random()); return (dice1 + dice2); } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

There is an issue with my Java program. I need to simulate a craps game, but two methods don't seem to be registering in the program. public boolean update() and public void printreport().

They need to represent the number of games played, percentage of games won and lost , current account balance, percentage increase or decrease in account balance since the session began in the ouput. The account balance in my program doesn't seem to be used even though it was inputed in the Dialog box. 

Program:

import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.util.Random;

public class Craps
{
double balance, startBalance, bet;
int wins, loss, games;
boolean win;
boolean eligibletoPlay;

public enum Status { CONTINUE, WON, LOST };
final static int SNAKE_EYES = 2;
final static int TREY = 3;
final static int SEVEN = 7;
final static int ELEVEN = 11;
final static int BOX_CARS = 12;
final static double MIN_BALANCE = 100.00;
final static double MIN_BET = 1.00;

Scanner input;
public static void main (String[] args) throws Exception
{
Craps game = new Craps();
game.AccountData();
game.NewGame();

}

public void NewGame()
{
String answer;
input = new Scanner(System.in);

while (true)
{
System.out.print("Do you wish to play another game? ");
answer = input.next();

if (answer.toLowerCase().charAt(0) == 'y')
{
play();

}
else if (answer.toLowerCase().charAt(0) == 'n')
{
printreport();
System.exit(5);
}
else
System.out.println("Please type in either 'y' to play again or 'n' to quit");

}
}

public boolean play()
{

int point = 0;
int sumOfDice = roll();
Status gameStatus;
switch (sumOfDice)
{
case SEVEN:
case ELEVEN:
gameStatus = Status.WON;
System.out.printf("Player rolls: %d\n", sumOfDice);
break;

case SNAKE_EYES:
case TREY:
case BOX_CARS:
gameStatus = Status.LOST;
System.out.printf("Player rolls: %d\n", sumOfDice);
break;

default:
gameStatus = Status.CONTINUE;
point = sumOfDice;
System.out.printf("Player rolls: %d\n", point);

}

while ( gameStatus == Status.CONTINUE )
{
sumOfDice = roll();
System.out.printf("Player rolls: %d\n", sumOfDice);
if (sumOfDice == point)
{
gameStatus = Status.WON;

}
else if (sumOfDice == SEVEN)
{
gameStatus = Status.LOST;

}
}

if ( gameStatus == Status.WON )
{
System.out.printf("Congratulations, You win\n\n", sumOfDice);

}
else
System.out.printf("Sorry, you've lost\n\n", sumOfDice, point);

NewGame();

return play();
}

public void AccountData()
{
String response;
JOptionPane.showMessageDialog(null, "Hello, and Welcome to the Craps Game;");
while (true)
{
response = JOptionPane.showInputDialog(null, "Enter your starting account balance ($)");
try
{
startBalance = Double.parseDouble(response);
}
catch (NullPointerException e)
{
JOptionPane.showMessageDialog(null, "Error: The box cannot be empty!");
continue;

}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Error: You must enter a numeric value in the box!");
continue;
}
if (startBalance >= MIN_BALANCE)
break;
System.out.printf("Please enter at least $%5.2f for a starting balance\n", MIN_BALANCE);


}

balance = startBalance;
wins = 0;
loss = 0;
games = 0;

play();
}

public boolean update ()
{
games++;
if (win)
{
wins++;
balance = balance - bet;
}
else
{
loss++;
balance = balance - bet;
}

System.out.printf("Your total account balance is now: %4.2f", balance);

if (balance < MIN_BET)
{
eligibletoPlay = false;
System.out.println("Sadly, you are no longer eligible to play");
}
return update();

}

public void printreport()
{
if (games > 0)
{
double changed = balance - startBalance;
double percentchanged = (changed/startBalance) * 100;
double percentwins = (wins/(double)games) * 100;
double percentlosses = (loss/(double)games) * 100;

System.out.printf("Of the %d games you have played you have won %d (%4.2f) , lost %d (%4.2f)", games, wins, percentwins, loss, percentlosses);

if (changed < 0 )
{
System.out.printf("Your balanced has decreased by %4.2f (%-4.2f)\n", changed, percentchanged);
System.out.printf("You have no more money left, bye\n");
}
else if (changed > 0)
{
System.out.printf("Your balanced has increased by %4.2f (%4.2f)\n", changed, percentchanged);
System.out.printf("Bye, enjoy your winnings");
}
}
}

public static int roll ()
{
int dice1;
int dice2;
dice1 = 1 + (int)(6.0*Math.random());
dice2 = 1 + (int)(6.0*Math.random());
return (dice1 + dice2);
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY