Advertisement
KarolPiechaczek

Untitled

Jan 22nd, 2022 (edited)
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package mathSkillTest;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String args[]) {
  7.         Number number = new Number();
  8.         int a = number.getFirstNumber(), b = number.getSecondNumber(),
  9.             result = number.getResult(), userResult = number.getUserResult(),
  10.             attempt, shoot = number.getShoot();
  11.        
  12.         Scanner scan = new Scanner(System.in);
  13.         System.out.println("How many attempts you need? ");
  14.         attempt = scan.nextInt();
  15.         number.setAttempts(attempt);
  16.        
  17.         String life = "<3";
  18.         System.out.println(a + " + " + b + " = ");
  19.        
  20.         while(userResult != result && attempt != 0) {
  21.             System.out.print("You have " + attempt + " lifes ");
  22.            
  23.             for(int i = 0; i < attempt; i++) {
  24.                 System.out.print(life + " ");
  25.             }
  26.             System.out.println();
  27.            
  28.             shoot++;
  29.             userResult = scan.nextInt();
  30.             if(userResult != result) {
  31.                 attempt--;
  32.                 System.out.println("Wrong, try again.");
  33.                 if(attempt == 0)
  34.                     System.out.println("you lost");
  35.             }
  36.             else {
  37.                 if(shoot == 1)
  38.                     System.out.println("Congrats. You did it in "+ shoot + " attempt.");
  39.                 else
  40.                     System.out.println("Congrats. You did it in "+ shoot + " attempts.");
  41.             }
  42.                
  43.         }
  44.         scan.close();
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement