1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

blackjack java

Discussion in 'Software Development' started by Galaxy_Tab, Nov 11, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. Galaxy_Tab

    Galaxy_Tab Thread Starter

    Joined:
    Nov 9, 2011
    Messages:
    9
    who can help to do it ??? i don't know how to do, i am studying the java.
     
  2. DoubleHelix

    DoubleHelix Banned

    Joined:
    Dec 9, 2004
    Messages:
    24,388
    Go to class, and do your own homework.
     
  3. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    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 :)
     
  4. Galaxy_Tab

    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".
     
  5. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    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 :)
     
  6. Galaxy_Tab

    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?
     
  7. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    2 Ways to do

    1. Assign the value to a separate variable
    2. Use methods with NON VOID return functions
     
  8. Galaxy_Tab

    Galaxy_Tab Thread Starter

    Joined:
    Nov 9, 2011
    Messages:
    9
    i dont get what you mean . I'm a total noob at this :(
     
  9. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    I got your PM with the code. I like to assist you in the thread rather than using PM :).. May I post your code here and correct it?
     
  10. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    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.
     
  11. Galaxy_Tab

    Galaxy_Tab Thread Starter

    Joined:
    Nov 9, 2011
    Messages:
    9
    I'm still not very sure how "this" works, feel free to edit the codes :)
     
  12. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    "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 :)
     
  13. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    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.
     
  14. Galaxy_Tab

    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()
    {

    }

    }
     
  15. Galaxy_Tab

    Galaxy_Tab Thread Starter

    Joined:
    Nov 9, 2011
    Messages:
    9
    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
     
  16. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1026414

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice