# Blackjack Program Not Calculating Totals Correctly

• 10-19-2011, 04:24 AM
skaterboy987
Blackjack Program Not Calculating Totals Correctly
I spent a while on this blackjack program. Here's how it doesn't work, This is the console:

Hello and welcome to blackjack
My name is david and i'll be your dealer
------------------------------------------------------------
Type Hit me for a card and Hold to stop the dealing
------------------------------------------------------------
Hit me
Your random card is a 0
Hit me
Your random card is a 10
Hit me
Your random card is a 4
Hold
You win! score of 4 to 4

```import java.util.Random; import java.util.Scanner; public class BlackJack {           public static void main(String[] args){                   Scanner scanner = new Scanner(System.in);                   int total = 0;                   int dTotal = 0; boolean bust = false; Init(); bust = dealerBust(dTotal, bust); for(int i=1; i<(25); i++) {         String input = scanner.nextLine(); if(input.equalsIgnoreCase("Hit me")){ int random = Random();        System.out.println("Your random card is a " + random); total = random + total;  } //Check if you went over if (total > 21){         System.out.println("Sorry, you went over 21");         break; } if(input.equalsIgnoreCase("Hold")){         System.out.println("Your total stays at " + total);         Hold(bust, i, i);         break; } }         }                     private static boolean dealerBust(int dTotal, boolean bust) {                 // TODO Auto-generated method stub                 for(int i=1; i<(25); i++)                 {                 int random1 = Random();                 dTotal = random1 + dTotal;                 if (dTotal >= 17){                         bust = false;                 break;                 }                 else if(dTotal > 21)                 {                         bust = true;                 }                 }                 return bust;                         }         private static void Hold(boolean bust,int total,int dTotal) {                 if(bust == false){                         if(total >= dTotal){                                 System.out.println("You win! score of " + total + " to " + dTotal);                         }                         else                                 {                                         System.out.println("You loose! score of " + total + " to " + dTotal);                                 }                         }                                         }                                                 public static int Random() {                 // TODO Auto-generated method stub                 Random randomGenerator = new Random();                 int randomInt = randomGenerator.nextInt(12);                 return randomInt;         }         private static void Init() {                 System.out.println("Hello and welcome to blackjack");                 System.out.println("My name is david and i'll be your dealer");                 System.out.println("------------------------------------------------------------");                 System.out.println("Type Hit me for a card and Hold to stop the dealing ");                 System.out.println("------------------------------------------------------------");                         } }```
`Hold(bust, i, i);`