Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.33 KB | None | 0 0
  1. package me.potato.applications;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         int suitpsn, suitcmp, nmbrpsn, nmbrcmp=0, nmbr2psn;
  10.         int nmbr2cmp = 0;
  11.         int nmbr3psn = 0;
  12.         int nmbr4psn = 0;
  13.         int nmbr5psn = 0;
  14.         int nmbr3cmp = 0;
  15.         int nmbr4cmp = 0;
  16.         int nmbr5cmp = 0;
  17.         int nmbr6cmp = 0;
  18.         int nmbr7cmp = 0;
  19.         int nmbr8cmp = 0;
  20.         int nmbr9cmp = 0;
  21.         int input1 = 0;
  22.         int input2 = 0;
  23.         int input3 = 0;
  24.         int psnsuml = 0;
  25.         int cmpsum = 0;
  26.         int counter=2;
  27.         int nxtcrd=0;
  28.  
  29.         Random r = new Random();
  30.         Random r2 = new Random();
  31.  
  32.         nmbrpsn = 2 + r2.nextInt(14);
  33.         if (nmbrpsn >= 12) {
  34.             nmbrpsn = 10;
  35.         }
  36.         nmbrcmp = 2 + r2.nextInt(14);
  37.         if (nmbrcmp >= 12) {
  38.             nmbrcmp = 10;
  39.         }
  40.         nmbr2psn = 2 + r2.nextInt(14);
  41.         if (nmbr2psn >= 12) {
  42.             nmbr2psn = 10;
  43.         }
  44.         nmbr2cmp = 2 + r2.nextInt(14);
  45.         if (nmbr2cmp >= 12) {
  46.             nmbr2cmp = 10;
  47.         }
  48.         cmpsum += nmbrcmp + nmbr2cmp;
  49.         System.out.println(" You drew " + nmbrpsn + " and " + nmbr2psn);
  50.         System.out.println("The computer has a " + nmbrcmp);
  51.  
  52.         Scanner user = new Scanner(System.in);
  53.  
  54.         if(nmbrpsn + nmbr2psn > 21) {
  55.             System.out.println("You busted. Game over.");
  56.         } else {
  57.  
  58.             System.out.println(" Do you want another card? 1 is yes 2 is no");
  59.             input1=user.nextInt();
  60.  
  61.             if (input1 == 1) {
  62.  
  63.                 nmbr3psn = 2 + r2.nextInt(14);
  64.                 if (nmbr3psn >= 12) {
  65.                     nmbr3psn = 10;
  66.                 }
  67.                 System.out.println("You drew " + nmbr3psn);
  68.                 if(nmbrpsn + nmbr2psn + nmbr3psn > 21) {
  69.                     System.out.println("You lose.");
  70.                 }else {
  71.  
  72.                     System.out.println(" Do you want another card? 1 is yes 2 is no");
  73.                     input2 = user.nextInt();
  74.  
  75.                     if (input2 == 1) {
  76.  
  77.                         nmbr4psn = 2 + r2.nextInt(14);
  78.                         if (nmbr4psn >= 12) {
  79.                             nmbr4psn = 10;
  80.                         }
  81.                         System.out.println("You drew " + nmbr4psn);
  82.                         if(nmbrpsn + nmbr2psn + nmbr3psn + nmbr4psn > 21) {
  83.                             System.out.println("You lose.");
  84.                         } else {
  85.                             System.out.println(" Do you want another card? 1 is yes 2 is no");
  86.                             input3=user.nextInt();
  87.  
  88.                             if (input3 == 1) {
  89.  
  90.                                 nmbr5psn = 2 + r2.nextInt(14);
  91.                                 if (nmbr5psn >= 12) {
  92.                                     nmbr5psn = 10;
  93.                                 }
  94.                                 System.out.println("You drew " + nmbr5psn);
  95.                                 if(nmbrpsn + nmbr2psn + nmbr3psn + nmbr4psn + nmbr5psn > 21) {
  96.                                     System.out.println("You lose.");
  97.                                 }
  98.                             }
  99.                         }
  100.                     }
  101.                 }
  102.             }else {
  103.                 if (cmpsum > 21) {
  104.                     System.out.println("The dealer busted. You win.");}
  105.                 else {
  106.                     while (cmpsum < 16) {
  107.  
  108.                         nxtcrd = 2 + r2.nextInt(14);
  109.                         if (nxtcrd >= 12) nxtcrd = 10;
  110.  
  111.                         cmpsum += nxtcrd;
  112.                         System.out.println("The computer drew a " + nxtcrd);
  113.                     }
  114.                 }
  115.             }
  116.         }
  117.  
  118.         System.out.println("The computer drew a " + nmbr2cmp);
  119.         System.out.println("Your total is " + (nmbrpsn + nmbr2psn + nmbr3psn + nmbr4psn + nmbr5psn));
  120.         System.out.println("Dealer total is " + cmpsum);
  121.  
  122.         if(nmbrpsn + nmbr2psn + nmbr3psn + nmbr4psn + nmbr5psn > cmpsum && nmbrpsn + nmbr2psn + nmbr3psn + nmbr4psn + nmbr5psn < 22) {
  123.             System.out.println("Your total was greater. You win.");
  124.         }else {
  125.             System.out.println("The dealer wins.");
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement