BlackJack when the user starts the game, he/she starts with an initial credit of
ID: 3637404 • Letter: B
Question
BlackJackwhen the user starts the game, he/she starts with an initial credit of $500, and the house starts with $5000.
The objective of the game is for the player to clean the house of all their money.
The default bet for each hand is $10. However, at the beginning of each hand, the player is given the option to up the stakes by increasing the bet up to whatever credit the player has left.
The rules are standard blackjack: the player gets 2 cards, and can see one of the cards dealt for the house. After this the player has two options: hit or stand. No double downs or splits.
The game is over if the player loses all of his/her credit.
You are to employ object oriented design in the design of your game: think of the relevant objects and create a class for each of them. Determine their attributes, behaviors, and interactions, and represent them accordingly with fields and methods. Also, consider representing the card deck as an array, and remember to reshuffle after every hand using a random number generator.
Explanation / Answer
import java.util.*; import java.io.*; import java.lang.*; public class BlackJackClassProject { public static void main(String[] args) throws IOException { BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in)); //Declare Variables int again = 0; do { double range = 26; int randomGenNum; int kitty = 500; int yourBet; int userHandValue = 0; int userDrawnValue; int dealerHandValue = 0; int dealerDrawnValue; String playAgain; String hit = ""; String strBetAmount; String userCard, dealerCard; int[] arrayCardValues = {0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10}; String[] arrayCardSuites = { "","","Ace/Clubs","Ace/Diamonds","Ace/Hearts","Ace/Spades", "2/Clubs","2/Diamonds","2/Hearts","2/Spades","3/Clubs","3/Diamonds","3/Hearts","3/Spades", "4/Clubs","4/Diamonds","4/Hearts","4/Spades","5/Clubs","5/Diamonds","5/Hearts","5/Spades", "6/Clubs","6/Diamonds","6/Hearts","6/Spades","7/Clubs","7/Diamonds","7/Hearts","7/Spades", "8/Clubs","8/Diamonds","8/Hearts","8/Spades","9/Clubs","9/Diamonds","9/Hearts","9/Spades", "10/Clubs","10/Diamonds","10/Hearts","10/Spades","Jack/Clubs","Jack/Diamonds","Jack/Hearts","Jack/Spades" ,"Queen/Clubs","Queen/Diamonds","Queen/Hearts","Queen/Spades","King/Clubs","King/Diamonds","King/Hearts","King/Spades" }; //ask the user how much they want to bet System.out.println("How much do you want to bet?"); strBetAmount = dataIn.readLine(); yourBet = Integer.parseInt(strBetAmount); //draw three cards (one card face up for dealer, two for player) //dealer first drawn card randomGenNum = (int)((range * Math.random()) + 1)*2; //assigning the dealer hand value & card, pulling index from array dealerHandValue = arrayCardValues[randomGenNum]; //Check if the dealer got an ace if ((randomGenNum >= 2) && (randomGenNum = 2) && (randomGenNum = 2) && (randomGenNum = 2) && (randomGenNumRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.