23.12.2019

Blackjack Program Java

28

A couple of quick observations:You repeat the code to get the numeric value of a card a few times - repeating code is never agood idea.You can put all that into a method public int getValue(String card). That you can call whenever you want the value of a card.In that method you can use a switch to avoid all those nested if statements.For a more 'object oriented' approach you would create a Card class that contains the name of the card and its numeric value.

Java Blackjack Source Code

ProgramBlackjack Program Java

You'll fund that tidies up and clarifies the code quite a lot. Yes, something along those lines is OK, at least for now.I can't do a complete into to OO here- there are lots aleady on the web, but for a card game you typically start with Card class (with members rank (Ace,2 etc) and suit). Then you have collection (eg ArrayList) of 52 Cards that you can shuffle and deal from. You have a Player class which has a collection ('hand') of Cards and methods to determine whnether that Player wants to twist or whatever. YOu may have a specialised sub-class of Player for the Dealer because the Dealer is almost but not quite the same as an ordinary player.All this puts you in a position where you can code the top-level so its so clear that it needs no comments. Player user1 = new Player;Dealer dealer = new Dealer;Deck deck = new Deck;deck.shuffle;user1.takeCards(deck.deal(2));if (user1.twists) then.