Jump to content

BlackJack Java

- - - - -

  • Please log in to reply
2 replies to this topic

#1
programming_nerd

programming_nerd

    Newbie

  • Members
  • Pip
  • 1 posts
A player is dealt an initial hand of two cards. He has the option of drawing cards to bring the total
value to 21 or less without exceeding it, so that the dealer will lose by having a lesser hand than
the player or by exceeding 21. The dealer also receives an initial hand of two cards.

However,
only the first card is visible to all. The other card is not visible until the dealer's turn. The dealer
starts his turn after every player stood (decided to take no more cards) or busted (value above
21). A player hits when he decides to take another card from the dealer. A player busts when his
hand value is above 21. When a player is busted, his chips is immediately forfeited regardless
whether the dealer is busted or not. When a dealer is busted, the remaining players who are not
busted wins. When there is a tie between the dealer and the player, the chips is returned to its
player.


Develop a Java program for the Blackjack card game. Do not implement additional options such as
"double", "split" or "surrender".
Required Functionality
 User registration of up to three players (A to C).
 Player's name must be at least three characters.
 Each player is to be given 100 chips at the beginning of the game.
 Dealer has unlimited amount of chips.
 Players cannot place chips of more than what they have.
 Each player or dealer has a hand of maximum five cards.
 Enforce turn-based dealing of cards to players.
 Display the value of a player's hand after a card is dealt.
 Allow players to stand or to hit.
 A player leaves the game when he has no more chips.
 The game ends when all players lose all their chips.
Coding Restrictions
 You must use simple (1-D) arrays in this assignment.
 You are not allowed to use 2-D arrays, ArrayList and LinkedList as your data structures.
 You are not allowed to implement any form of GUI (E.g. Swing, AWT, etc.)



Sample Output
Players Registration
B L A C K J A C K
================================================================================
Enter number of players (1-3) > 3
Enter Name of Player A > Ben
Enter Name of Player B > Joy
Enter Name of Player C > Frank
B L A C K J A C K
================================================================================
Enter number of players (1-3) > 2
Enter Name of Player A > He
*** NAME TOO SHORT!
Enter Name of Player A > Bee
Enter Name of Player B > Jude

Displaying the Game
================================================================================
Player A, You have 100
Enter number of chips to play > 100
Player B, You have 100
Enter number of chips to play > 100
Player C, You have 100
Enter number of chips to play > 80
--------------------------------------------------------------------------------
DEALER
<Heart Ace>
--------------------------------------------------------------------------------
Player A
<Club Five>
<Club Ace>
[H]it or [S]tand S
PLAYER A : Joe
Value : 16
Hand : <Club Five> <Club Ace>
--------------------------------------------------------------------------------
Player B
<Heart Two>
<Diamond Nine>
[H]it or [S]tand H
<Spade Two>
[H]it or [S]tand H
<Diamond Four>
[H]it or [S]tand H
<Diamond Ace>
[H]it or [S]tand S
PLAYER B : Ben
Value : 18
Hand : <Heart Two> <Diamond Nine> <Spade Two> <Diamond Four> <Diamond Ace>
--------------------------------------------------------------------------------
Player C
<Spade Jack>
<Diamond Jack>
[H]it or [S]tand S
PLAYER C : Tay
Value : 20
Hand : <Spade Jack> <Diamond Jack>

DEALER
Value : 21
Hand : <Heart Ace> <Spade Queen>
DEALER
Value : 21
Hand : <Heart Ace> <Spade Queen>
================================================================================
Player A. Lost 100
Player B. Lost 100
Player C. Lost 80
================================================================================
Player C, You have 20
Enter number of chips to play > 20
--------------------------------------------------------------------------------
DEALER
<Heart Four>
--------------------------------------------------------------------------------
Player C
<Spade Ten>
<Heart Six>
[H]it or [S]tand H
<Spade Six>
PLAYER C : Tay
Value : 22
Hand : <Spade Ten> <Heart Six> <Spade Six>
--------------------------------------------------------------------------------
DEALER
Value : 14
Hand : <Heart Four> <Club Ten>
[H]it or [S]tand S
DEALER
Value : 14
Hand : <Heart Four> <Club Ten>

Player C. Busted. Lost 20
G A M E O V E R








Various Messages Displayed During Game Play
================================================================================
Player A. Won 80.
Player B. Tied with Dealer.
Player C. Busted. Lost 100.
Player A, You have 100
Enter number of chips to play > 120
*** YOU CANNOT PLAY MORE THAN WHAT YOU HAVE.
Player A, enter amount of chips to play >

I got to create four classes BlackJackGame, Deck, Player and Card and a keyboard class is given to me.

The BlackJackGame consists of

dealer : Player
players : Player[]
deck : Deck
numPlayer : int

main(String []) : void
start() : void
registerPlayers() : void
ask PlayersPlaceChips() : void
dealCardsToDealer() : void
dealCardsToDealer2() : void
dealCardsToPlayers() : void
determineWinLoseOrTie() : void
isGameOver() : boolean

Deck class consists of

deck : Card[52]
cardsDispensed : int

Deck()
dispenseCard() : Card
createDeck() : void
shuffleDeck() : void

Card class consists of

suit : int
number : int

Card(int, int)
getScore() : int
getTitle() : String
display() : void

Player class consists of

id : char
name : String
chips : int
stake : int
hand : Card[5]

Player(Char, String)
leftGame() : boolean
placeStake(int) : void
win() : void
lose() : void
hit(Card) : void
valueOfHand() : int
clearHand() : void
displayStatus() : void


Currently here is my Deck Class

public class Deck {

	public Deck[] Card = new Deck[52];

	public int cardsDispensed;

	

   public Deck(){

	   

   }

   public Card dispenseCard() {

	   

   }

   

   public void createDeck(){

	   

   }

	

   public void shuffleDeck(){

	   

   }

}

there is a red line beneath the dispenseCard() . I do not know what is wrong with it.


My card class


public class Card {

	public int suit; 

	public int number; 

	

	private final String[] Digit = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

    private final String[] Symbol = {"Spade", "Heart", "Diamond", "Club"};

	

	public Card(int suit, int number){

		this.suit = suit;

		this.number = number; 

	}

	public int getScore(){

		return number;

	}

	public int getTitle(){

		return suit;

	}

	public void display(){

		String value = Digit[number];

		String shape = Symbol[suit];

		System.out.println(shape + " " + value);

		

		

	}

}

I have not work on my BlackJack class. Anyone knows how to help?? Thanks alot man

Edited by Roger, 19 November 2011 - 09:27 PM.
added code tags


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Which part do you need help with?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Eieio

Eieio

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts

WingedPanther said:

Which part do you need help with?

I think he wants us to write the BlackJack class.

_____________

Could you put it in code tags and I will help. Really hard to read without it man. Sorry.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users