Question: I have identified a bug that causes the program to terminate unexpectedly when I ' m done with the game. When I click no to
I have identified a bug that causes the program to terminate unexpectedly when Im done with the game. When I click no to not play again or when I click yes when out of bankroll money, the game crashes. Can you debug this code below and fix it
import java.util.Scanner;
import java.util.Random;
public class PlayingCard
private int face;
private String suit;
private static final String SUITS Hearts "Diamonds", "Clubs", "Spades";
private static final int FACES ;
public PlayingCard
Random rand new Random;
this.face FACESrandnextIntFACESlength;
this.suit SUITSrandnextIntSUITSlength;
public int getFace
return this.face;
public boolean isEqualsPlayingCard other
return this.face other.face;
@Override
public String toString
return this.face of this.suit;
public static void mainString args
Scanner input new ScannerSystemin;
int totalGames ;
int totalWins ;
int totalLosses ;
int totalTies ;
double bankroll;
do
System.out.printEnter your bankroll: $;
while input.hasNextDoublebankroll input.nextDouble
System.out.printlnInvalid input. Please enter a positive real number.";
input.nextLine;
double initialBankroll bankroll;
int gamesPlayed ;
int wins ;
int losses ;
int ties ;
while bankroll
gamesPlayed;
System.out.printEnter your bet between $ and $: $;
double bet;
while input.hasNextDoublebet input.nextDouble bet
System.out.printlnInvalid bet amount. Please enter a value between $ and $;
input.nextLine;
if bet bankroll
System.out.printlnInsufficient funds. You have $ bankroll left in your bankroll.";
continue;
PlayingCard cardOne new PlayingCard;
PlayingCard cardTwo new PlayingCard;
System.out.printlnCard drawn: cardOne;
System.out.printHigher or lower? hl: ;
char guess Character.toLowerCaseinputnextcharAt;
if guess h && cardTwo.getFace cardOne.getFace
guess l && cardTwo.getFace cardOne.getFace
bankroll bet;
System.out.printlnCorrect You won $ bet;
wins;
else if cardTwogetFace cardOne.getFace
System.out.printlnIts a tie!";
ties;
else
bankroll bet;
System.out.printlnIncorrect You lost $ bet;
losses;
System.out.printlnYour bankroll: $ bankroll;
System.out.printDo you want to play again? yn: ;
input.nextLine;
String playAgain input.nextLine;
if playAgain.equalsIgnoreCasey
break;
System.out.println
Game Summary ;
System.out.printlnTotal games played: gamesPlayed;
System.out.printlnTotal wins: wins;
System.out.printlnTotal losses: losses;
System.out.printlnTotal ties: ties;
System.out.printlnEnding amount in bankroll: $ bankroll;
System.out.printlnInitial bankroll: $ initialBankroll;
totalGames gamesPlayed;
totalWins wins;
totalLosses losses;
totalTies ties;
System.out.println
Overall Summary ;
System.out.printlnTotal games played: totalGames;
System.out.printlnTotal wins: totalWins;
System.out.printlnTotal losses: totalLosses;
System.out.printlnTotal ties: totalTies;
input.close;
while true;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
