🔥 object oriented - OOP implementation of Blackjack in Java - part 2 - Code Review Stack Exchange

Most Liked Casino Bonuses in the last 7 days 🎰

Filter:
Sort:
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Implementation. The game is written in Java (developed in Eclipse) using Swing/​AWT for the GUI. Standard Blackjack rules are used: Dealer stands on 16; Aces.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

We'll also start to make use of a few of the many Java library classes. Create a class called Blackjack that implements a simple version of the card game.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Java programs are built from classes and interfaces. a collection of methods that are to be implemented by a class.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

We'll also start to make use of a few of the many Java library classes. Create a class called Blackjack that implements a simple version of the card game.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

BlackJack code in Java. Dimension; public class BlackJack extends JFrame implements ActionListener { private static final int WIDTH =


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Guess who has a flash back? Smaller things: Deck: I can't see any declaration of that type. 2chat.rue(): Is only called within the.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Implementation. The game is written in Java (developed in Eclipse) using Swing/​AWT for the GUI. Standard Blackjack rules are used: Dealer stands on 16; Aces.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Java programs are built from classes and interfaces. a collection of methods that are to be implemented by a class.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

Your suitToString() should really be implemented with a switch statement. (Not an error.) Your 2chat.ru and 2chat.rulue members make no sense, and.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

🍒

Software - MORE
A7684562
Bonus:
Free Spins
Players:
All
WR:
30 xB
Max cash out:
$ 200

The program needs an object of class Deck and two objects of type BlackjackHand, one for the dealer and one for the user. The general object in Blackjack is to.


Enjoy!
Valid for casinos
Visits
Likes
Dislikes
Comments
implement blackjack in java

Smaller things: Deck : I can't see any declaration of that type. Arrays; import java. When everyone including the house has played his turn, it could initiate the payout handling. So, you will always end with an exception. What exactly is the main responsibility of a Dealer? And calling anything around that. So which are the logical classes to model an actual real life dealer and what are their responsibilities? First a quick point about the L in SOLID Liskov substitution principle : The principle says that if you are handling an AbstractPlayer anywhere in your code, then it shouldn't matter if it's an instance of AbstractPlayer or an instance of Dealer. The concrete implementations are tightly coupled to its super class. Nilzone- Nilzone- 1, 1 1 gold badge 14 14 silver badges 26 26 bronze badges. It's much more flexible, easier to maintain and what not. I my mind it makes sense to have a base class we can inherit from since player and dealer share so much common functionality? Active Oldest Votes. AbstractPlayer : is not abstract AbstractPlayer : The hand is not private it is implementation of abstraction, and should not be accessible to implementation of the abstraction The upper one should call the lower one with 1 as parameter. CardDeck : Not sure if you have to pass the Suit[] and Rank[] array for the initializer methods. Actually, I think that's what you have to change to satisfy Liskov's law Bold, as I am, I've taken the liberty of doing so with your post. Just think about testing your calculateScore method. He also pointed out that something feels wrong with your Dealer class but his explanation of what it is exactly isn't clear. My main concern with this implementation is the use of Inheritance A base Player vs having that as a interface - as that would lead to duplicate code in both Player and Dealer classes. Meaning: Do not use inheritance for code reuse. If the Deck is empty the Dealer will first shuffle the previously collected cards and renews the deck. I just wanted to give a general idea on what it could be. But I would still really appreciate a review of this new version. The HousePlayer , just like any other player, asks the Dealer for cards until it's pleased with his hand. It also isn't allowed to split or double down. Another general rule is composition over inheritance. It doesn't play the game himself. If you want to enhance it later: Add the method with the two parameters again, and delegate the call from the no-param method to the newly added one.

Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Wait a minute And he has to have at least 17 and can't hold before that. A main object oriented principle is "lose coupling", inheritance can be, as I think it is in your case, the opposite.

I think it's enough to explicitly declare a Dealer and a Player in that case. Everything works - the last thing for me to implement is having the dealer try to get to 21 after implement blackjack in java the players. So when it's a player's turn he can ask this Dealer for a card.

Or is it responsible for "playing" the house's hand acting like an AbstractPlayer. The "H" and "S" is duplicated, that should be a constant with a proper name - maybe even provided in the enum itself String symbol as constructor of the enum?

And: I can't find the place, where you actually check, if there's no card left? Actually, like Slowy pointed out, the house player has strict rules on when to hold, so it's fully deterministic.

Let's call this one HousePlayer for now. I thought as long as my fix didn't mess with other peoples reviews change things they talk about in their reviewit was OK.

Rank : Can't remember, if I have ever seen a non-private constructor in an enum and I didn't know you can implement blackjack in java do that.

You might want to add some functionalities to handle resetting when the deck is empty for example. And if he has an ace and and already 17, the ace must be counted as So, actuallyyour dealer read article a player, only the drawing of the cards is different, isn't it?

If you want to, you can post that as a partial review of your own code, but don't change the original question after answers has arrived. However, it doesn't make any sense, since noone else can call it anyway?

Since that is another layer of abstraction and thus violates the Single responsibility principle again. Also: You have an empty default case. Imus Imus 4, 5 5 silver badges 25 25 bronze badges.

Hope that helps I'm still unsure of the inheritence-part though. To see how these should be split up, let's look at what actually happens in a game of poker. The best answers are voted up and rise to the top. I would say that it shouldn't calculate payouts himself. So initializeMultipleDecks will be initializeDecks, and initializeDeck can be removed. Since the code won't ever reach that point, I'd throw an Exception - if that happens, a bug has been introduced. The answer is both. Collectors; import java. Or: How to you want to reuse that method, without being a player? Last we have the Dealer which does not extend AbstractPlayer. Also: the default case will return null. I've rolled back your fix to the bug. Pass a player's request for a card to a CardDeck , or pass the CardDeck to a player when it's his turn implementation detail. Viewed 1k times. Next we have the CardDeck that's already handling the shuffling and keeping track of the cards. Then, you also get rid of the duplicate shuffle call. Inheritance A main object oriented principle is "lose coupling", inheritance can be, as I think it is in your case, the opposite. Immagine you have a Dealer that is only responsible for handling the deck of cards. Deck; import java. A thing to notice here is that the Dealer is now using composition mostly. My main problem with that, you can neither test the abstraction without a implementation, nor can you test a implementation without its abstraction. Home Questions Tags Users Unanswered. Calling it AbstractPlayer is a little misleading considering it's not.. Eg if a player has AAA7, that would be 20, but you calculate it as You are absolutely right. Why do you need a concrete implementation to test that method? Asked 3 years, 1 month ago. If you don't like it, you can rollback my edit by clicking on the edited by link below your post. I think it's okay, to get the values from the enum itself. We have a HousePlayer that is an AbstractPlayer with it's own rules on asking for cards and holding. So it could for example tell the CardDeck to initialise. Active 3 years, 1 month ago. It only takes a minute to sign up. I hope someone corrects me, if I'm wrong, or describes it better: I always had a hard time understand the L and I usually have other reasons to avoid inheritance. It contains a HousePlayer, a deck of cards, a list of players, But it isn't any of those himself. Slowy has already pointed out most of the small things. Sign up to join this community. When it's the "dealers" turn to play we can treat this as another player. It doesn't matter that it's an instance of Dealer at all, the expected behaviour stays exactly the same, so you do not violate that principle here. ArrayList; import java. There's a lot of articles and discussions about pros and cons and questions to ask which help on your decision making in the interwebs - there's also a section in the Design Pattners Book, I think. He is responsible for telling each player to "play" when it's their turn. I will fix that. This is a bit weird here since you can't directly instantiate an abstract class but the principle stays the same. Part 1.