Advertisement
Guest User

Untitled

a guest
May 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. public class BMI {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         Scanner input = new Scanner(System.in);
  6.         String userName1;
  7.         String userName2;
  8.         int pile1 = 3;
  9.         int pile2 = 4;
  10.         int pile3 = 5;
  11.         String kupka = "";
  12.         int ile;
  13.         int usrSwitch = 2;
  14.  
  15.         System.out.println("Podaj nazwe użytkownika nr 1: ");
  16.         userName1 = input.nextLine();
  17.         System.out.println("Podaj nazwe użytkownika nr 2: ");
  18.         userName2 = input.nextLine();
  19.         int counter = 1;
  20.  
  21.         while (counter != 0) {
  22.             System.out.println("A:   " + pile1 + "    B:   " + pile2 + "   C:   " + pile3);
  23.             if (usrSwitch % 2 == 0) {
  24.                 System.out.println(userName1 + ", twoja kolej. Która kupka?");
  25.             } else {
  26.                 System.out.println(userName2 + ", twoja kolej. Która kupka?");
  27.             }
  28.             kupka = input.next();
  29.             while (pile1 == 0 && kupka.equalsIgnoreCase("A")) {
  30.                 System.out.println("Ta kupka jest pusta.  Wybierz jeszcze raz: ");
  31.                 kupka = input.next();
  32.             }
  33.             while (pile2 == 0 && kupka.equalsIgnoreCase("B")) {
  34.                 System.out.println("Ta kupka jest pusta.  Wybierz jeszcze raz: ");
  35.                 kupka = input.next();
  36.             }
  37.             while (pile3 == 0 && kupka.equalsIgnoreCase("C")) {
  38.                 System.out.println("Ta kupka jest pusta. Wybierz jeszcze raz: ");
  39.                 kupka = input.next();
  40.             }
  41.             if (kupka.equalsIgnoreCase("A")) {
  42.                 System.out.println("Ile chcesz zabrać?");
  43.                 ile = input.nextInt();
  44.                 while (ile > pile1 || ile < 0) {
  45.                     System.out.println("Nie wolno oszukiwać! Spróbuj jeszcze raz!");
  46.                     ile = input.nextInt();
  47.                 }
  48.                 pile1 = pile1 - ile;
  49.  
  50.             }
  51.             if (kupka.equalsIgnoreCase("B")) {
  52.                 System.out.println("Ile chcesz zabrać?");
  53.                 ile = input.nextInt();
  54.                 while (ile > pile2 || ile < 0) {
  55.                     System.out.println("Nie wolno oszukiwać! Spróbuj jeszcze raz!");
  56.                     ile = input.nextInt();
  57.                 }
  58.                 pile2 = pile2 - ile;
  59.  
  60.             }
  61.             if (kupka.equalsIgnoreCase("C")) {
  62.  
  63.                 System.out.println("Ile chcesz zabrać?");
  64.                 ile = input.nextInt();
  65.                 while (ile > pile3 || ile < 0) {
  66.                     System.out.println("Nie wolno oszukiwać! Spróbuj jeszcze raz!");
  67.                     ile = input.nextInt();
  68.                 }
  69.                 pile3 = pile3 - ile;
  70.  
  71.             }
  72.             if (pile3 == 0 && pile1 == 0 && pile2 == 0) {
  73.                 counter = 0;
  74.  
  75.             }
  76.             usrSwitch += 1;
  77.         }
  78.         if (usrSwitch % 2 == 0) {
  79.             System.out.println("Gra zakonczona, przegrał " + userName2);
  80.         } else {
  81.             System.out.println("Gra zakonczona, przegrał " + userName1);
  82.         }
  83.  
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement