Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* * * In java * * * how do I improve this game? I can't figure out how to draw and read the cards

***In java*** how do I improve this game? I can't figure out how to draw and read the cards correctly: import java.util.*;
import java.util.ArrayList;
public class BlackJack{
public static void main(String[] args){int bets;
int bank =500;
int hit;
int playAgain =0;
Deck gameDeck = new Deck();
Card gameCard = new Card();
int drawnCards =0;
int dealerTotal =0;
ArrayList bjDeck = new ArrayList<>();
Scanner input = new Scanner(System.in);
do{
System.out.println("Welcome to Blackjack you have $"+ bank);
System.out.println("Place your bets");
bets = input.nextInt();
System.out.println("Here are your 2 cards");
gameDeck.drawCard();
bjDeck.add(gameDeck);
gameDeck.drawCard();
bjDeck.add(gameDeck);
System.out.println(bjDeck.get(0)+""+ bjDeck.get(1));
System.out.println("Total is: "+ "add drawn cards");
System.out.println("Do you want a hit? 1= yes 2= no");
hit = input.nextInt();
if(hit ==1){
//draw another card and add to previous cards
//draw 2 dealer cards from the same deck and total them
System.out.println("Dealer Total "+ "total dealer cards");
if(dealerTotal <=21 && drawnCards >21){
System.out.println("Dealer Wins");
bank = bank - bets;
}
else{
System.out.println("Dealer Busted");
bank = bank + bets;
}
}
else if(hit ==2){
//draw 2 dealer cards from the same deck and total them
System.out.println("Dealer Total "+ "total dealer cards");
if(dealerTotal <=21 && dealerTotal > drawnCards){
System.out.println("Dealer Wins");
bank = bank - bets;
}
else{
System.out.println("Dealer Busted");
bank = bank + bets;
}
}
System.out.println("Your Bank: $"+ bank);
System.out.println("Do you want to play again? 1= yes 2= no");
playAgain = input.nextInt();
}while(playAgain !=2);
}
}

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

More Books

Students also viewed these Databases questions