Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have to code a simple blackjack game. my code works and meets the expectations except for the fact that the same numbers keep being

i have to code a simple blackjack game. my code works and meets the expectations except for the fact that the same numbers keep being generated in the same krder each time and i dont know how to fix it so a different random number is generated each run.
image text in transcribed
image text in transcribed
image text in transcribed
STC/Blackjack java src/blackjack.java P1Random.java ArithmeticException Java Black Jackmackjack.java 1 import java.util.Scanner; 2 import java.util. Random 3 4 public class Blackjack 7 public static void main(String[] args) { 8 int menu = 1: int Number: 10 Scanner sehr = new Scanner(System.in); 11 P1Random randomen new P1 Randon(); 12 Int userHand = 0; 13 int dealerHand = 0; chines int player in = 8; 15 int dealerii = ; 16 int tieGame = 0; 17 int gamesPlayed = 0; 15 int percentagelins = 0; 29 int startGate 1: 20 System.out.println("START GAME #1"); 21 System.out.println(); 22 B while (menu = 4){ 1 (menu == 1) { 24 my Number randomben.nextInt( limit: 14); 25 26 if (myNumber ss 11) { 27 System.out.println("Your card is a JACK!"); 28 } else CnyNumber - 12) { 29 System.out.println("Your card is a QUEEN!"); 38 } else if (my Number 13) { 32 System.out.println("Your card is a KINGI"); } else if (myNumber - 1) 35 System.out.println("Yobt card is a ACEI"); 34 } else { System.out.println("Your card is a " + my Number + "1"); 38 } 37 System.out.println(); 38 1 (myNumber > 10) { 39 User Hand - WeChand 10; 40 System.out.println("Your hand is: " + user Hand); 43 } else { user Hand my Number + User Hand iler Buld Settings. I ignore this update today 8:18 AM 30 "Kotlin" plu Update PI VW 720)Mon 9:27 AM Project 1 -Blackjack.java Alth Exceptionave BlackJackamaiachack.jare r/Blackjack PIRandom olse { user Hand myNumber user Hand: System.out.println("Your hand is: userland) > if (userland - 21) { System.out.println("BLACKJACK You wint"); Systes.out.println(); startlane stactare . 1; System.out.println("START GAME " startGame): Systes.out.println(): 40 49 58 51 52 chines 56 55 56 57 58 99 60 61 O 02 65 65 } else if (menu s 2) { my Number = randomen.nextInt( limit: 10) . 16; dealer Hand - RYNumber: System.out.println("Dealer's hand: . dealer hand) System.out.println("Your band is: " . wecland) System.out.println(); f (user Hand e 21) { System.out.println("BLACKJACK You wint"); gamesPlayed Played1; player in playerwin. 1: } else sy (user Hand sa dealerland){ System.out.println("It's a tie! No one wins"); gamesPlayed - ganesPlaved + 1; tiene = ticGame . 1 } else 17 (userland > 21) { System.out.println("You exceeded 211 You lose."); gamesPlayed game played 1 dealer in dealerwin. 1: } else 11 (dealerland > 21) { System.out.println("You wint'); gamesPlayed atsplayed. 1; player = player in 1: } else if (dealer Hand > Wsciand){ System.out.println("Dealer wins!"); dealer in dealer. 1 ganesPlayed - GamePlayed = 1; } else! System.out.println("You wini"): player in . player in 11 gansplayed gamesPlayed. 1; 67 69 71 73 7 77 20 "Kotlin" plugin update avalle UpdatePlugin Settings ner Build Semings ignore this update ay 8 AM 4:46 LA w G 72) Mon 9:28 AM Project 1 - arc/inckjack.java Blackjack Arithmeticotinjava Black Jackmellackiek javaw/ Random.jave Systes.out.println("Dealer Wing To dealen - dealer. 1; 77 QARASPlayed ganesPlayed + 1; 7 else { 79 System.out.println("You win!"); playewin - playerlin. 1; 31 ganes Played - gamesPlayed 15 23 > System.out.println(); 14 start one start13 05 System.out.println("START SAME #". startGame); 6 System.out.println(); Ls 1 (menu se 3){ Machines percentagelins = player.in/ QARD Played 09 Systes.out.println("Number of Player wins: ".playerlin) System.out.println("Number of Dealer wies: . dealer in) 01 System.out.println("Number of tie ganes!". tilane) 92 System.out.println("Total of games played is: .gamesplayed): System.out.println("Percentage of Player wins: percentagelins) 96 System.out.println(): } else if (n) { System.out.println("Same over"); 97 } else { System.out.println("Invalid input!"): System.out.println("Please enter an Integer value between 1 and 4."); 100 System.out.println(); > 102 Systes.out.println("1. Get another card"); System.out.println("2. Hold hand) Foot 104 System.out.println("3. Print statistics"); 165 System.out.println("4. Exit); 165 System.out.println(); 102 System.ovt.println("Choose an Lotion:") 100 menu = sonr.nextInt(): 109 Kotlin" plugin update avalla Update Paginating Duld hagin Betings. Ignore this updated 18 AMI 49:45

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_2

Step: 3

blur-text-image_step3

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

ISBN: 3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

Calculate the elevations of points A and B in Problem 27.19.

Answered: 1 week ago

Question

Name and briefly describe the capabilities of a DBMS.

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago