Guest User

Untitled

a guest
May 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import TerminalIO.KeyboardReader;
  2. import java.util.Random;
  3.  
  4. public class BlackJack {
  5. public static void main (String [] Args){
  6. KeyboardReader reader = new KeyboardReader();
  7. Random generator = new Random();
  8.  
  9. int card1;
  10. int card2;
  11. int card3;
  12. int card4;
  13. int choice;
  14. int over21;
  15. int under21;
  16. int game;
  17. int numb;
  18. int numb2;
  19. int numb3;
  20.  
  21. System.out.print("Do you want to play a game? [1 to continute]: ");
  22. choice = reader.readInt();
  23.  
  24. while(choice == 1){
  25.     if (choice >=2){
  26.         System.out.println("Do you quit?");
  27.     }else{
  28.     choice++;
  29. card1 = generator.nextInt(12) + 1;
  30. card2 = generator.nextInt(12) + 1;
  31.  
  32.  
  33. numb = card1 + card2;
  34. System.out.println("Here are your two cards: "+card1+ " "+card2);
  35. System.out.println(card1+ " and " +card2+ " are equal to " +numb);
  36. if(numb >21)
  37.         System.out.println("You lose!");
  38. if(numb ==21)
  39.         System.out.println("You win!");
  40.  
  41. if(numb <=22){
  42.     System.out.print("Do you want another card? Yes [1], No [2]: ");
  43.     choice = reader.readInt();
  44.     while(choice == 1){
  45.         choice++;
  46.         card3 = generator.nextInt(12) + 1;
  47.         numb2 = numb + card3;
  48.         System.out.println("You got a " +card3);
  49.         System.out.println("Your cards add up to "+numb2);
  50.         if(numb2 >21)
  51.         System.out.println("You lose!");
  52.         if(numb ==21)
  53.         System.out.println("You win!");
  54.  
  55. if(numb2 <=22){
  56.     System.out.print("Do you want another card? Yes [1], No [2]: ");
  57.     choice = reader.readInt();
  58.     while(choice == 1){
  59.         choice++;
  60.         card4 = generator.nextInt(12) + 1;
  61.         numb3 = numb2 + card4;
  62.         System.out.println("You got a " +card4);
  63.         System.out.println("Your cards add up to "+numb3);
  64.         if(numb3 >21)
  65.         System.out.println("You lose!");
  66.         if(numb ==21)
  67.         System.out.println("You win!");
  68.  
  69.  
  70.  
  71.     }
  72. }
  73. }
  74. }
  75. }
  76. }
  77.  
  78. }
  79. }
Add Comment
Please, Sign In to add comment