Given this sample code

import java.util.ArrayList;
import blackjack.model.items.Card;

public class BlackJackPlayer extends Player {

    private double bet;

    private Hand hand01 = new Hand();
    private Hand hand02 = new Hand();

    public void addCardToHand01(Card c) {

    public void addCardToHand02(Card c) {

    public void bustHand01() {

    public void bustHand02() {

    public void standHand01() {

    public void standHand02() {

    public boolean isHand01Bust() {
        return hand01.isBust();

    public boolean isHand02Bust() {
        return hand02.isBust();

    public boolean isHand01Standing() {
        return hand01.isStanding();

    public boolean isHand02Standing() {
        return hand02.isStanding();

    public int  getHand01Score(){ return hand01.getCardScore(); }

    public int  getHand02Score(){ return hand02.getCardScore(); }


Is this considered as a repetitive code? providing that each method is operating a seperate field but doing the same implementation ? Note that hand01 and hand02 should be distinct.

if this is considered as repetitive code, how would I address this? providing that each hand is a seperate entity


Your mixing the game code with the player class. You should have a class for the player and one for the game(BlackJack). You need to start with something like this:

public class Player 
    private double bet;
    private string name;

    public Hand hand = new Hand();

    public Player(string name)
         this.name = name'

    public Hand getHand(){
        return hand;


public class BlackJack
     private List<Player> players = new ArrayList<Player>(); ;

     public BlackJack(Player player1, Player player2)

     public void bustHand(int playerNum) throws IndexOutOfBoundsException 


I am coding on the spot so it will not working 100% but should give you an idea

  • I have another class does this exact same thing, in this class I made the user have two hands just in case he is eligible for split. – KyelJmD Oct 22 '12 at 2:36
  • 1
    You can add a list of hands to the player class like list<Hands> hands; To do that. – user60802 Oct 22 '12 at 2:42
  • so it's better to have it as a list? – KyelJmD Oct 22 '12 at 2:43
  • 3
    Yes, writing the same code over and over is real bad. – user60802 Oct 22 '12 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.