
Int you = 21-handvalue //check who is closer to 21 and determine winner If(2*bet21)//if the dealer busted, user wins. ("You win 2x your money back!") Įlse if(dealer.hasBlackJack())//check if the dealer has blackjack. If(hasBlackJack(handvalue) & dealer.hasBlackJack())//check if both the user and dealer have blackjack.Įlse if(hasBlackJack(handvalue))//check if the user has blackjack. ("You start with cash: "+cash) ĭeck deck = new Deck() //initialize deck, dealer, hands, and set the bet. ("How much cash do you want to start with?") ("Hello, "+name+", lets play some BlackJack!") Private static String name //name of the user Private static int handvalue //the value of the user's hand If(handvalue hand //represents the user's hand * Takes the turn for the dealer and returns the value of his hand. * Determines if the dealer wants to hit according to classic Blackjack rules. * Gives the dealer another card and updates the value of his hand. * Prints the dealer's first card (the card face up at the beginning of a blackjack game). Private int AceCounter //counts the aces in the dealer's hand Private Card aHand //used to convert the dealer's hand to an array Private int handvalue=0 //value of the dealer's hand (starts at 0) Private ArrayList deck //represents a deck of cardsįor(int i=0 i hand //represents the dealer's hand * Creates and shuffles a deck of 52 playing cards. If a jack, queen, or king the value is ten. * the rank and suit of an individual card. * Created with an integer that represents a spot in the String array ranks and the String array suits. Private int value //represents the value of a card

Private int suit //represents the suit of a card Private int rank //represents the rank of a card
#BLACKJACK GAME JAVA NETBEANS CODE#
I want to implement insurance and splitting, so any advice to help prepare the code for eventually adding those features would be really helpful! Finally, my main method is pretty long - I was wondering if this is typical of Java programs and, if not, how I can fix that. I was wondering, seeing as it is my first multi class program, if you could help me optimize it and/or give me any advice. * value the value of this rank in a Blackjack game.I just completed my first multi class program, Blackjack, and it works! It allows the user to play Blackjack against a single dealer, with no other players at the table. * args the default parameter no arguments neededīlackjackController game = new BlackjackController() įor (Person person : blackjack.getPlayers()) values and ranks. * Creates an instance of this class and calls #run()}. * For each new game it creates an instance of Blackjack} I also added comments to most every class and method.īlackjackController.java package blackjack.Added HandDisplay to help with describing the contents of a Hand in plain English.I have split off a Hand class from the Person class.I have changed to Card class to be an enum, so the available cards better represents an actual deck.I have given the Blackjack class less functions (moved most of them to the new ConsoleView and BlackjackController classes.I think it has made parts of my code messier than they were before. Besides that, I tried to implement the MVC pattern better, but this confused me a lot. I think I have treated every issue that was put up by the previous reviewers. I have got some good reviews and since then I have been trying to improve the code. A couple of days ago I posted the code for my Simple Blackjack console game.
