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 2 of 2

Thread: Black Jack Statistics game? lost.

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Black Jack Statistics game? lost.

    Hey everyone I'm writing a program that simulates a blackjack game not a playable game but one to find the statistics if you win or lose and find the percents. This is as far as i have gotten and I'm not stuck and at a complete loss. Any ideas or suggestions would be helpful.
    PHP Code:
    import java.util.*; 
    public class 
    BlackjackSkeletonNoRand {

        public static 
    void main(String[] args) {

            
    String outcome;
            
    int trials 100;
            
    int wins 0losses 0pushes 0;
            
    int rand=(int)(13*Math.random()+1);
            
            
    //Starts the loop for each trial and prints if its a win or a loss.
            
    for ( int i 1<= trialsi++){
                
    outcome blackjack(rand);
                
    System.out.println("The player has a " outcome "\n");
                if ( 
    outcome.equals("win"))
                    
    wins++;
                else if (
    outcome.equals("loss"))
                    
    losses++;
                else
                    
    pushes++;                
            }

            
    System.out.println("For " trials 
                            
    " hands of blackjack, the totals are:\n"
                            
    "wins = " wins "\nlosses = " losses 
                            
    "\npushes = " pushes);
            
    System.out.println("% wins = " + (double) wins/trials 100 
                            
    "      % losses = " + (double)losses/trials  100
                            
    "    % house advantage = " 
                            
    + (double)(losses wins)/trials 100);    
        }

        
    // Returns "win", "loss" or "push"
        
    public static String blackjack (int cardvalue){
            
    int numPlayerAces 0;
            
    int numDealerAces 0;
            
    int playerTot 0;
            
    int dealerShows =0;
            
    int hole;
            
            
    // First card to player, face up         
            
    int currentCard cardValue();
            
            if (
    currentCard == )
                
    numPlayerAces++;
            else
                
    playerTot currentCard;
            
            
    printCurrentPlayerHand(currentCardplayerTotnumPlayerAces);

            
    // First card to dealer, face up        
            
    currentCard cardValue();
            if ( 
    currentCard == )
                
    numDealerAces++;
            else
                
    dealerShows currentCard;
            
            
    printCurrentDealerHand(currentCarddealerShowsnumDealerAces,0);

            
    // Second card to player, face up         
            
    currentCard cardValue();
            if (
    currentCard == )
                
    numPlayerAces++;
            else
                
    playerTot += currentCard;
            
            
    printCurrentPlayerHandcurrentCardplayerTotnumPlayerAces);

            
    // Second card to dealer, face down         
            
    hole cardValue();
            
    printCurrentDealerHand(holedealerShowsnumDealerAces,hole);
            
            
    int dealerPrivateTot;
            if ( 
    hole == )
                
    dealerPrivateTot dealerShows 
                                  
    computeAces(numDealerAces 1dealerShows);
            else
                
    dealerPrivateTot dealerShows hole 
                               
    computeAces(numDealerAcesdealerShows);


            
    // Test for immediate bust or blackjack with push or win.l   
            
            
    int acesValue computeAces(numPlayerAcesplayerTot);
            while (
    playerTot acesValue 21 )
            {
               
    // your code here
                
    playerTot += 10;  // This is here just to make the loop terminate.  Delete it.
            
    }
            
            if ( 
    playerTot acesValue 21)
                return 
    "loss";
            
            while (
    dealerPrivateTot 17 )
            {      
                
                
            }
            
            if (
    dealerPrivateTot 21 )
                return 
    "win";
            
            
            
    playerTot += computeAces(numPlayerAcesplayerTot);
            
            if (
    playerTot == dealerPrivateTot)
                return 
    "push";
            
            if (
    playerTot dealerPrivateTot)
                return 
    "win";
            
            return 
    "loss";


        }
        
        
    // method cardValue()
        // Returns the value of the card.  10 - 13 are 10.  2 - 9 are that value, 
        // 1 is ace and returned as 1.
        
    public static int cardValue(int rand){
            
    int cardValue rand;
            if (
    cardValue>=10)
                
    cardValue=10;
            else 
    cardValue=rand;
            return 
    cardValue;       
        }
        

     
    // method computeAces() returns the total current value of all the aces
     // given the current total and the number of aces, return the total value of the aces.
     //  e.g.  total = 7, numAces = 2,  returns 12, 1 ace is 11 and the other is 1. 
     // Note:  Only 1 ace can be 11.
        
    public static int computeAces(int numAcesint cardValue){
            
    int cards cardValue;
            
    int ace 1;
            if (
    cards+ace<=21)
                
    ace=11;
            else 
                
    ace=1;
            
    numAces=ace;
           return 
    numAces;
        }
     
    // methods  printCurrentPlayerHand() and printCurrentDealerHand()
    // In printCurrentDealerHand if the hole card is an ace, it is not counted in the number of aces.
        
    public static void printCurrentPlayerHand(int aint b int c){
            
        }
        public static 
    void printCurrentDealerHand(int aint b int cint d){
            
        }
        



  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: Black Jack Statistics game? lost.

    And what's the question? What's not working? Where are you stuck? Be specific.

Similar Threads

  1. I'm lost
    By stoptheerrors in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 31st, 2010, 08:47 AM
  2. Im lost....
    By brale76578 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 31st, 2010, 08:09 AM
  3. lost
    By nyny in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 7th, 2010, 07:32 AM
  4. useing the comp's phone jack
    By wolfgar in forum Java Theory & Questions
    Replies: 10
    Last Post: November 7th, 2009, 03:57 PM
  5. How to save statistics of a game in a binary file instead of txt file?
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 19th, 2009, 05:05 AM