Black Jack

// Black Jack

import java.io.*;
class Blackjack
{
public static void main() throws IOException
{
BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
System.out.println(“Welcome to the game of blackjack!!!!!!!”);
System.out.println();
System.out.println();
System.out.println(“You will be drawing two cards.”);
System.out.println(“The Dealer will also be drawing two cards.”);
System.out.println();
System.out.println();
boolean userWins;
int userwin=0,dealerwin=0;
char ch;
do
{
userWins = playBlackjack();
if (userWins)
{
userwin++;
}
else
{
dealerwin++;
}
System.out.println(“Total number of wins for Dealer = “+ dealerwin);
System.out.println(“Total number of wins for You = “+ userwin);
System.out.println();
System.out.println();
System.out.println(“Want to play another hand?”);
System.out.print(“Enter ‘Y’ for Yes and ‘N’ for No: “);
do
{
ch = Character.toUpperCase( (char)in.read() );
if (ch != ‘Y’ && ch != ‘N’)
System.out.print(“Please respond H or S: “);
}while (ch != ‘Y’ && ch != ‘N’);

if (ch == ‘N’)
{System.out.println(“Thank you for playing!!!!”);break;}
for (int i=0;i<20;i++)
{
System.out.println();
}
}while (ch == 'Y');
}
static boolean playBlackjack()throws IOException
{
BufferedReader in= new BufferedReader( new InputStreamReader(System.in));
int usertot=0,dealertot=0,card=0,r=0;
r=(int) (Math.random()*10);
if (r==1)
{card= r*10+1;}
else
{card= r;}
usertot = usertot +card;
r=(int) (Math.random()*10);
if (r==1)
{card= r*10+1;}
else
{card= r;}
usertot = usertot +card;
r=(int) (Math.random()*10);
if (r==1)
{card= r*10+1;}
else
{card= r;}
dealertot = dealertot + card ;
r=(int) (Math.random()*10);
if (r==1)
{card= r*10+1;}
else
{card= r;}
dealertot = dealertot + card ;
System.out.println("Your total after drawing two cards = "+usertot);
System.out.println("Dealer's total after drawing two cards = "+dealertot);
System.out.println();
System.out.println();
if (dealertot == 21)
{
System.out.println();
System.out.println("Dealer has Blackjack.Dealer wins!!!!");
return false;
}
if (usertot == 21)
{
System.out.println();
System.out.println("You have Blackjack.You win!!!!");
return true;
}
int userCards=2,dealerCards=2;
while (usertot < 21 && dealertot 21)
{
System.out.println();
System.out.println(“You lost by going over 21!!!!”);
return false;
}
if(usertot == 21)
{
System.out.println();
System.out.println(“You win as your total is 21!!!!”);
return true;
}
}
}
System.out.println();
System.out.println(“You stand.”);
while (dealertot 21)
{
System.out.println();
System.out.println(“Dealer lost by going over 21. You win!!!!”);
return true;
}
}
System.out.println(“Dealer’s total is ” + dealertot);
System.out.println();
System.out.println();
if (dealertot == usertot)
{
System.out.println(“Dealer wins on a tie.You lose!!!!”);
System.out.println();
return false;
}
else if (dealertot > usertot)
{
System.out.println(“Dealer wins, ” + dealertot+ ” points to ” + usertot + “!!!!”);
System.out.println();
return false;
}
else
{
System.out.println(“You win, ” + usertot+ ” points to ” + dealertot+ “!!!!”);
System.out.println();
return true;
}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s