Results 1 to 2 of 2

Thread: blackjack help

  1. #1
    jordaejava is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default blackjack help

    i have my cards printed to the screen but i cant make the dealer any thoughts here is my code

    this is the Card Class

    import javax.swing.*;
    public class CardClass {
    private int suitInt, valueInt, valueInt2,valueInt3,valueInt1,suitInt1;
    private String suitString,suitString1;
    private String suit[]={"Hearts","Spades","Diamonds","Clubs"};
    private int value[]={2,3,4,5,6,7,8,9,10,11};

    public void setSuit(){
    suitInt=(int)(Math.random()*4);
    suitString = suit[suitInt];
    }

    public String getSuit(){
    return suitString;
    }

    public void setValue(){
    valueInt=(int) ((Math.random()*10));
    valueInt2= value[valueInt];
    }

    public int getValue(){
    return valueInt2;
    }
    public void setsuit(){
    suitInt1=(int)(Math.random()*4);
    suitString1 = suit[suitInt1];
    }

    public String getsuit(){
    return suitString1;
    }

    public void setvalue(){
    valueInt1=(int) ((Math.random()*10));
    valueInt3= value[valueInt1];
    }

    public int getvalue(){
    return valueInt3;
    }

    }
    This is my main class
    import javax.swing.*;
    import java.util.*;
    public class BlackJack1 {
    public static void main(String [] args){
    String myInput;
    CardClass card=new CardClass();
    String s,v;
    int totalCards = 0;
    int card1Val, card2Val;
    double bet=0.0;
    boolean gameDone = false;
    myInput=JOptionPane.showInputDialog("Welcome to the Black jack table care to play\n1-yes\n2-no");

    if(myInput.equals("1")){
    myInput=JOptionPane.showInputDialog("Place your bet");
    bet=Double.parseDouble(myInput);
    System.out.println("Your current bet is $" + bet);
    JOptionPane.showMessageDialog(null,"here are your cards sir");
    card.setValue();
    card.setSuit();

    System.out.println(card.getValue() + " of " + card.getSuit());
    card1Val = card.getValue();
    card.setValue();
    card.setSuit();
    System.out.println(card.getValue() + " of " + card.getSuit());
    card2Val = card.getValue();

    totalCards=card1Val + card2Val;
    System.out.println("your total amount is " + totalCards);
    }
    /////////////////////////////
    while(gameDone == false){
    myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay"+"\n3-Surrender" +"\n4-doubledown"+"\n5-Done turn");
    if(myInput.equals("1")){
    card.setValue();
    card.setSuit();
    System.out.println(card.getValue() + " of " + card.getSuit());
    totalCards+=card.getValue();
    System.out.println("your new total is " + totalCards);
    if(totalCards>21){
    System.out.println("bad luck buddy you break");
    gameDone = true;
    }
    }
    if(myInput.equals("2")){
    //totalCards=card.getValue() + card.getCardValue();
    System.out.println("your new total is " + totalCards);
    }
    if(myInput.equals("3")){
    bet= bet/2;
    System.out.println("$"+bet);
    System.exit(1);
    }
    if(myInput.equals("4")){
    bet=bet*2;
    System.out.println("$"+bet);
    card.setvalue();
    card.setsuit();
    System.out.println(card.getvalue() + " of " + card.getsuit());
    totalCards+=card.getvalue();
    System.out.println("your Total amount is " + totalCards);

    if(totalCards>21){
    System.out.println("sorry but you busted");
    System.exit(1);
    }
    }

    if(myInput.equals("5")){
    System.out.println("now it's the dealers turn");
    myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay"+"\n3-Surrender" +"\n4-doubledown"+"\n5-Done turn");
    System.out.println(card.getValue() + " of " + card.getSuit());
    card1Val = card.getValue();
    card.setValue();
    card.setSuit();
    System.out.println(card.getValue() + " of " + card.getSuit());
    card2Val = card.getValue();
    totalCards+=card.getValue();
    System.out.println("your new total is " + totalCards);


    while(gameDone == false){
    myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay");
    if(totalCards<15){
    myInput=1;
    }
    if(myInput.equals("1")){
    card.setValue();
    card.setSuit();
    System.out.println(card.getValue() + " of " + card.getSuit());
    totalCards+=card.getValue();
    System.out.println("your new total is " + totalCards);
    if(totalCards>21){
    System.out.println("i breakguess you win");
    gameDone = true;
    }else

    if(myInput.equals("2")){
    //totalCards=card.getValue() + card.getCardValue();
    System.out.println("your new total is " + totalCards);
    }

    }
    }
    }
    }
    }
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Compiling your (renamed) code:
    Java Code:
    C:\jexp>javac bj.java
    bj.java:87: incompatible types
    found   : int
    required: java.lang.String
                            myInput=1;
                                    ^
    1 error
    When it's the dealer's turn call a method that will automatically play the dealers hand, score it and return the final result, eg, a score or a special code for 'busted'. Then you can finish up the round in you main loop.

Similar Threads

  1. My blackjack games random generator doesnt work!
    By Addez in forum New To Java
    Replies: 16
    Last Post: 08-17-2009, 05:29 AM
  2. Multiplayer BlackJack Applet
    By lostwake in forum Java Applets
    Replies: 0
    Last Post: 07-23-2009, 11:04 PM
  3. Need ideas and help for a simple BlackJack Game
    By Dannii in forum New To Java
    Replies: 5
    Last Post: 04-27-2009, 10:53 AM
  4. Help with simple Blackjack Program?
    By meeper3000 in forum New To Java
    Replies: 2
    Last Post: 04-26-2009, 09:46 AM
  5. BlackJack help please,, adding hand values
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •