Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER TO ALL MY QUESTIONS PLEASE AND THANK YOU. WHAT DO YOU SEE AS MISTAKE ON THOSE LINE: LINE 129, 43 ,86, 140, 141, 147,

ANSWER TO ALL MY QUESTIONS PLEASE AND THANK YOU.

WHAT DO YOU SEE AS MISTAKE ON THOSE LINE: LINE 129, 43 ,86, 140, 141, 147, 186, 176, 206, 155, OR LINE: 39, 86, 142, 147, 155, 176, 178, 211. FIND 6 Problems fixed: Line number and new code. THANK YOU

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

import java.util.Random; import java.util.Scanner;

/** */ public class BuggyBlackjack {

private Scanner stdIn = new Scanner(System.in);

private Random random = new Random(0L); // in production, you would want to randomize program behavior // by seeding the random number generator with the clock value, // but while debugging, you want the generated numbers to repeat, // so we comment out the production statement and seed it with 0 // in the line above // private static Random random = new Random(System.currentTimeMillis());

private int netUserWinnings; private int amountOfCurrentBet; private int userWins; private int ties; private int userLosses;

/** * This method asks for and sets the bet amount */ private void getAmountOfBet() { int amountOfCurrentBet = 0;

System.out.println("How much do you want to bet on this hand?"); amountOfCurrentBet = stdIn.nextInt(); while (amountOfCurrentBet

/** * The method generates a random number between 1 and 13 * @return the random number generated */ private int dealNextCard() { return random.nextInt(13) + 1; }

/** * This method returns a string value for the card parameter * @param card a card in the range of 1 to 13 * @return the rank of the card from Ace to King */ private String stringForCard(int card) { if (card == 1) { return "A"; } else if (card

/** * This method reports the value of the parameter card * @param card a card in the range of 1 to 13 * @return the point value of the card. */ private int valueOf(int card) { if (card > 10) { return card - 10; } else { return card; } }

/** * This method prints the current value of the user's winnings */ private void reportCurrentWinnings() {

System.out.print("At this time "); if (netUserWinnings > 0) { System.out.println("I owe you " + netUserWinnings + " dollars."); } else if (netUserWinnings

/** * The method plays a single hand of Blackjack * calls: getAmountOfBet() * reportCurrentWinnings() */ private void playOneHand() { char reply;

boolean userBusted; boolean userWantsACard = false;

int dealersHoleCard; int dealersNextCard; int usersHoleCard; int usersNextCard; int countOfCardsToUser = 2; int countOfCardToDealer = 2; int sumOfUserCards; int sumOfDealerCards;

getAmountOfBet();

usersHoleCard = dealNextCard(); dealersHoleCard = dealNextCard(); usersNextCard = dealNextCard(); dealersNextCard = dealNextCard();

System.out.println("My cards are : X " + stringForCard(dealersNextCard)); System.out.println("Your cards are : " + stringForCard(usersHoleCard) + ' ' + stringForCard(usersNextCard));

sumOfUserCards = valueOf(usersHoleCard) + valueOf(usersNextCard); sumOfDealerCards = valueOf(dealersHoleCard) + valueOf(dealersHoleCard);

// allow user to ask for more cards System.out.println("Another card?"); reply = stdIn.next().charAt(0); userWantsACard = reply == 'y' && reply == 'Y'; while (sumOfUserCards = 22) { userLosses++; netUserWinnings -= amountOfCurrentBet; System.out.println("You busted!"); } else { // Dealer tips over the hole card System.out.println("My cards are: " + stringForCard(dealersHoleCard) + ' ' + stringForCard(dealersNextCard)); // dealer takes cards until reaches 17 while (sumOfDealerCards 21) { System.out.println("I busted! You win!"); netUserWinnings += amountOfCurrentBet; } else if (sumOfDealerCards >= sumOfUserCards) { userLosses++; System.out.println(sumOfDealerCards + " beats " + sumOfUserCards + ", so I win!"); netUserWinnings -= amountOfCurrentBet; } else if (sumOfDealerCards

System.out.println("Want to play a hand of blackjack?"); reply = stdIn.next().charAt(0); userWantsToPlay = reply == 'y' || reply == 'Y';

while (userWantsToPlay) { playOneHand(); System.out.println("Play another?"); reply = stdIn.next().charAt(0); }

System.out.println("You can settle up with the cashier."); System.out.println("You won " + userWins + " hands, lost " + userLosses + " hands, and " + ties + " hands were ties."); } /** * The main method * @param args the command line arguments */ public static void main(String[] args) { BuggyBlackjack driver = new BuggyBlackjack(); driver.run(); } }

8 package buggyblackjack; 9 10 import java.util. Random; 11 import java.util.Scanner; 12 13 / 14 15 * @author aapplin 16 17 public class BuggyBlackjack { 18 19 private Scanner stdIn = new Scanner(System.in); 20 21 private Random random = new Random(OL); 22 // in production, you would want to randomize program behavior 23 // by seeding the random number generator with the clock value, 24 // but while debugging, you want the generated numbers to repeat, 25 // so we comment out the production statement and seed it with o 26 // in the line above 27 // private static Random random = new Random (System.currentTimeMillis(); 28 29 private int netUserwinnings; 30 private int amountOfCurrentBet; 31 private int userwins; 32 private int ties; 33 private int user Losses; 34 35 36 + This method asks for and sets the bet amount 37 38 private void getAmountOfBet() { 39 int amountOfCurrentBet = 0; 40 41 System.out.println("How much do you want to bet on this hand?"); 42 amountOfCurrentBet = stdin.nextInt(); 43 while (amountofCurrentBet 10) { return card - 10; } else { return card; } 1 * This method prints the current value of the user's winnings private void reportCurrentWinnings() { 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 IF System.out.print("At this time "); if (netUserwinnings > 0) { System.out.println("I owe you " + netUserWinnings + " dollars."); } else if (netUserwinnings 22) { userLosses++; netUserwinnings -= amountofCurrentBet; System.out.println("You busted!"); } else { 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 } if (sumo fUserCards >= 22) { userLosses++; netUserWinnings -= amountOfCurrentBet; System.out.println("You busted!"); } else { // Dealer tips over the hole card System.out.println("My cards are: + stringForCard (dealersHoleCard) + !! + stringForCard(dealersNextCard)); 17 dealer takes cards until reaches 17 while (sumofDealerCards 21) { System.out.println("I busted! You win!"); netUserWinnings += amountOfCurrentBet; } else if (sumofDealerCards >= sumofuserCards) { userLosses++; System.out.println (sumofDealerCards + " beats" + sumOfUserCards +", so I win!"); netUserWinnings -- amountOfCurrentBet; } else if (sumofDealerCards

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions