import java.io.*;
import java.util.*;
class blackjack
{
// **** Global Variables ****
	private static Random ran = new Random ();
	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	
// ###########  MAIN  #################
	public static void main(String args[]) throws Exception
	{
		// ****  Variables  ****
		boolean play=true;
		int bank=100;
		String input;
		int playerHand [] = new int [5];
		int compHand [] = new int [5];
		int playerCardCount=0;
		int compCardCount=0;
		int bet=0;
		
		// display instructions
		instructions();
		// main game loop repeat until user quits
		while (play)
		{
			// **** Variables for While Loop ****
			boolean validBet=false;
			boolean hit=true;
			boolean pBust=false; // player bust
			boolean cBust=false; // computer bust
			int compTotal=0;
				
			playerCardCount=2;
			compCardCount=2;
			
			
			// **** Ask for bet ****
			while (!validBet)
			{
				System.out.println("You have $"+bank);
				System.out.println("Bets must be greater than $5");
				System.out.print("Place your bet: ");
				input = br.readLine();
				bet = Integer.parseInt(input);
				validBet = bet <= bank && bet >= 5;
			}
			
			
			// deal cards to player and comp
			playerHand[0]=deal();
			playerHand[1]=deal();
			compHand[0]=deal();
			compHand[1]=deal();
			
			//display cards
			displayStatus (playerHand, compHand, playerCardCount);
			
			// ask hit or stand
			System.out.print ("(H)it or (S)tand : ");
			input=br.readLine();
			hit = input.equals("H") || input.equals("h");
			
			// loop until stand
			while (hit && playerCardCount<4 && !pBust)
			{
				// deal card 
				playerHand[playerCardCount++]=deal();

// !!!!!!!!!!!!! UPDATE HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!								
					// test wether player has busted				

				displayStatus (playerHand, compHand, playerCardCount);
				
				// ask hit or stand if not bust
				if (!pBust)
				{	
					System.out.print ("(H)it or (S)tand : ");
					input=br.readLine();
					hit = input.equals("H") || input.equals("h");
				}
				else
				{
					System.out.println ("You Bust Sucker");
				}
			}
					
			// loop until comp has 17 or over as long as user hasn't bust
		// BACK HERE	
			compTotal=total(compHand, compCardCount);	
			while (compTotal<17 && compTotal<=21))
			{
				// deal card to comp
				compHand[compCardCount++]=deal();
			}
			
			// eval winner
			// ask play again
			// get response	
		
		
		}
		
		
	}
	
	
// ###########  TOTAL  #################
	// total of all the cards in a hand
	private static int total(int [] h, int c)
	{
		int sum=0;
		
		for (int i=0; i<c-1; i++)
		{
			System.out.println("i: "+i);
			System.out.println("h ["+i+"]: "+h[i]);
			sum = sum + h[i];
		}
		return (sum);
	}

// ###########  DEAL  #################
	// deal one card
	private static int deal()
	{
		return (ran.nextInt(12)+1);
	}
	
// ###########  INSTRUCTIONS  #################
	private static void instructions()
	{
		System.out.println("Welcome to Blackjack\n");
		
	}
	
// ###########  DISPLAY STATUS  #################
	// display cards on table
	private static void displayStatus (int [] p, int [] c,int pc )
	{
		System.out.print("Your cards are: ");
		
		for (int i=0; i<pc; i++)
// !!!!!!!!!!!!! UPDATE HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!			
			// CHANGE TO PRINT TRANSLATED VERSIONS OF CARDS
			System.out.print(p[i]+" ");
		System.out.println("\nThe computer is showing: "+c[0]);
	}

// ###########  TRANSLATE  #################
	// translate int card value into string
	
// ###########  GETCARDVAL  ################
	// translate int into the actual value of the card
	private int getCardVal(int c)
	{
// !!!!!!!!!!!!! UPDATE HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		// Should return the game value of a card		
		return (c);	
	}	


// ###########  PLAYERWINS  #################
	// eval winner
			// if no bust
				// find out who wins
				// give money
			// else if user not bust
				// give money
	
}