blackjack java

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.
Joined
May 20, 2010
Messages
4,040
Welcome to TSG

Need to develop a GAME with a superb GUI ? What is your JAVA level?. Anyway, here we correct codes, we do not give the complete code :)
 

Galaxy_Tab

Thread Starter
Joined
Nov 9, 2011
Messages
9
@sepala Just a basic version of this game.I'm a beginner in programming language
So how do i store these ???

suit int Card
Possible values: 0 to 3
Represents "Spade", "Diamond", "Club", "Heart".

suit int Card
Possible values: 0 to 12
Represents "Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack",
"Queen", "King".
 
Joined
May 20, 2010
Messages
4,040
Hi,

Actually I have no idea about this game, because of that it could be very hard for me to find what you are trying to do. My apologies for that.

Anyway the answer for HOW TO STORE VALUES is, use Variables. In your case, you will need the help of "IF ELSE" condition too.

For an example, have a look below.

Code:
public class BlackJack
{
    public static void main(String[]args)
    {
        String spade= "SPADE";
        String diamond = "DIAMOND";
        String club = "CLUB"
        int i=0;

       if(i==0)
       {
          System.out.println(spade);
        }
       else if(i==1)
       {
           System.out.println(diamond);
       }
       else if(i==2)
       {
          System.out.println(club);
        }
}
}
This is just a small example to show how to use Variables, and how to address the MAIN part of your issue. You have to change these according to your need. Apart from that, you might want to get the user input to check what the CARD THEY PLAY is. For that you need to use STREAMS. I didn't use any of those here, because I wanted to keep this simple as possible.

Ask any question you have :)
 

Galaxy_Tab

Thread Starter
Joined
Nov 9, 2011
Messages
9
Thanks for the tips but what should i do if i want to return the value instead of printing?
 
Joined
May 20, 2010
Messages
4,040
2 Ways to do

1. Assign the value to a separate variable
2. Use methods with NON VOID return functions
 
Joined
May 20, 2010
Messages
4,040
Anyway, you have coded it better than I thought. Good Job :)..

At a glance, there are no errors in the code, and no possible runtime errors too. But I can't exactly say that because you haven't provide the full code. However, there is something that you MUST learn. Learn where to use "this" keyword and where not to use. You have used that in several places where it is not needed.
 

Galaxy_Tab

Thread Starter
Joined
Nov 9, 2011
Messages
9
Anyway, you have coded it better than I thought. Good Job :)..

At a glance, there are no errors in the code, and no possible runtime errors too. But I can't exactly say that because you haven't provide the full code. However, there is something that you MUST learn. Learn where to use "this" keyword and where not to use. You have used that in several places where it is not needed.
I'm still not very sure how "this" works, feel free to edit the codes :)
 
Joined
May 20, 2010
Messages
4,040
"this" keyword is a keyword used to access "class cope variables". This is mainly used INSIDE A METHOD if the method has parameters WHICH ARE SIMILAR TO CLASS COPE VARIABLES. I will edit your code, no problem, but it will be posted tomorrow because now I am in a middle of a project :)
 
Joined
May 20, 2010
Messages
4,040
You code is sent to you via PM.

Here what you have to learn...

1. Avoid unnecessary keywords in unnecessary places.
2. Arrange the code well. Use proper alignments. Then only it will be programmer friendly.
3. Don't use method names like "toString()". They are already defined methods in JAVA, in your case it didn't make any issues, but other people might get confused on that. (toString() is a powerful built in method in JAVA. It is defined inside OBJECT, the ROOT of the java classes)
4. When you give your code to someone to check, give the full code, or at least enough parts to RUN the code.
5. When you are using names for variables, avoid giving similar names such as "Number","NUMBER","number" etc.
 

Galaxy_Tab

Thread Starter
Joined
Nov 9, 2011
Messages
9
I'm stuck with the Deck class this is the code i have done so far.I'm not sure why is there an error in Card dispenseCard()

import java.util.Random;

public class Deck
{

// Fields of Deck class
public Deck[] Card = new Deck[52];
public int cardsDispensed;

// Method of Deck class

public Deck()
{
Deck d = new Deck();

// Prints the deck in order with 0 card used starting from Spade Ace to Heart King
System.out.println("An ordered deck (Card Used: " + d.dispenseCard() + ")");
System.out.println(d);
System.out.println();

d.shuffleDeck();
}

public Card dispenseCard()
{

}

public void createDeck()
{

}

public void shuffleDeck()
{

}

}
 

Galaxy_Tab

Thread Starter
Joined
Nov 9, 2011
Messages
9
I'm stuck with the Deck class this is the code i have done so far.I'm not sure why is there an error in Card dispenseCard()

import java.util.Random;

public class Deck
{

// Fields of Deck class
public Deck[] Card = new Deck[52];
public int cardsDispensed;

// Method of Deck class

public Deck()
{
Deck d = new Deck();

// Prints the deck in order with 0 card used starting from Spade Ace to Heart King
System.out.println("An ordered deck (Card Used: " + d.dispenseCard() + ")");
System.out.println(d);
System.out.println();

d.shuffleDeck();
}

public Card dispenseCard()
{

}

public void createDeck()
{

}

public void shuffleDeck()
{

}

}
This is the class diagram

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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top