Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Blackjack

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Blackjack

    I'm working on a program to simulate a game of blackjack and I'm a bit stuck. I want to have a running score that would be "score + value" after each card is dealt, I know I'm going the wrong way about it but just can't figure it out, any help is greatly appreciated!

    import java.util.Scanner;
    import java.util.Random;

    class blackjack{
    public static void main(String args[]){

    Scanner in = new Scanner(System.in);



    int value, score=0;
    String card1, card2, card3, card4, card5, play1, play2, play3;

    Random random = new Random();

    String[] suit = {"Spades", "Hearts", "Clubs", "Diamonds"};
    int selectS = random.nextInt(suit.length);

    String[] rank = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
    int selectR = random.nextInt(rank.length);

    card1 = (rank[selectR] + " of " + suit[selectS]);
    card2 = (rank[selectR] + " of " + suit[selectS]);
    card3 = (rank[selectR] + " of " + suit[selectS]);
    card4 = (rank[selectR] + " of " + suit[selectS]);
    card5 = (rank[selectR] + " of " + suit[selectS]);

    if(selectR >=9 ) {
    value = 10;
    }

    if(selectR ==0 && score < 22) {
    value = 11;
    }

    if(selectR ==0 && score > 21){
    value = 1;
    }

    if(selectR >0 && selectR<9 ) {
    value = selectR+1;
    }

    System.out.println(card1);
    System.out.println(card2+"\nRunning score : "+score);

    System.out.print("\nHit or stay?");
    play1 = in.nextLine();
    if(play1.equals("hit")){
    System.out.println(card3+"\nRunning score : "+score);
    }

    System.out.print("\nHit or stay?");
    play2 = in.nextLine();
    if(play2.equals("hit")){
    System.out.println(card4+"\nRunning score : "+score);
    }

    System.out.print("\nHit or stay?");
    play3 = in.nextLine();
    if(play3.equals("hit")){
    System.out.println(card5+"\nRunning score : "+score);
    }






    } //end main
    } //end class


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Blackjack

    When posting code, please use the highlight tags and standard naming conventions.

    I don't see any place in this code where you set or increment the score variable.

    Also, have you not learned about loops yet?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    gavinqotsa92 (November 28th, 2013)

  4. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Blackjack

    I just learned about loops today and got it working, thanks for the help!

Similar Threads

  1. Blackjack game
    By roscowgo in forum Java Theory & Questions
    Replies: 5
    Last Post: January 17th, 2012, 12:21 PM
  2. BlackJack Help
    By programming_nerd in forum Object Oriented Programming
    Replies: 5
    Last Post: November 22nd, 2011, 03:21 AM
  3. BlackJack Java
    By programming_nerd in forum Member Introductions
    Replies: 0
    Last Post: November 19th, 2011, 07:14 AM
  4. Help with blackjack game
    By santosd1118 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 12th, 2010, 12:55 AM
  5. A little help with my Blackjack code
    By Neophyte in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 3rd, 2010, 01:13 PM

Tags for this Thread