import java.util.Scanner;
public class Deck {
public static void main(String[] args) {
int deal=(int)(11*Math.random()+1);
int deal1=(int)(11*Math.random()+1);
int deal2=(int)(11*Math.random()+1);
int deal3=(int)(11*Math.random()+1);
Scanner input = new Scanner(System.in);
int sum;
int sum1;
int player;
int dealer;
// deal two cards to the player
System.out.println( "your cards are:");
System.out.println( player=deal);
System.out.println(player=deal1);
System.out.println("your total cards are:");
System.out.println(sum1=deal+deal1);
dealer=deal2;
dealer=deal3;
sum=deal2+deal3;
if(sum1==21&&sum==21){
System.out.println("The player wins");
}
else if (sum==21){
System.out.println("dealer wins");
}
else if(sum1==21){
System.out.println("Player wins");
}
// variables for when each player is finished hitting
boolean iamdone = false;
boolean dealerDone = false;
String answer;
while(!iamdone || !dealerDone) {
// player's turn
while(!iamdone){
System.out.print("Hit or Stay? (Enter H or S): ");
answer = input.nextLine();
// if the player hits
if(answer.equals("H")) {
// add next card and store whether we've busted
int deal4=(int)(11*Math.random()+1);
System.out.println(player=deal4);
System.out.println("your total is");
System.out.println(sum1=deal+deal1+deal4);
}
else if(sum1==21){
System.out.println("player wins");
}
else if(sum1>21){
System.out.println("player score over 21, you lose");
}
else{
System.out.println("Dealers turn");
}
}
// dealer's turn
dealerDone=sum<17;
while(!dealerDone){
int deal5=(int)(11*Math.random()+1);
System.out.println("The Dealer hits");
dealer=deal5;
sum=deal2+deal3+deal5;
if (sum==21){
System.out.println("dealer wins");
}
else if(sum>21){
System.out.println("dealer score over 21, player wins");
}
else{
System.out.println("dealer stays");
}
}
}
}
}