Advertisement
jwrbg

asd

Apr 20th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package ProgrammingBasics;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Vacantion {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int moneyForVacantion = Integer.parseInt(scanner.nextLine());
  9.         int availableMoney = Integer.parseInt(scanner.nextLine());
  10.         int counterDays = 0;
  11.         int counterMoney = 0;
  12.  
  13.         while (true) {
  14.             String action = scanner.nextLine();
  15.             int amountInAction = Integer.parseInt(scanner.nextLine());
  16.             counterDays++;
  17.             if (action.equals("spend")) {
  18.                 if (amountInAction > availableMoney) {
  19.                     availableMoney = 0;
  20.                 } else {
  21.                     availableMoney -= amountInAction;
  22.                 }
  23.                 counterMoney++;
  24.             }
  25.             if (counterMoney >= 5) {
  26.                 System.out.println("You can't save the money.");
  27.                 System.out.printf("%d", counterDays);
  28.                 break;
  29.  
  30.             } else if (action.equals("save")) {
  31.                 counterMoney = 0;
  32.                 availableMoney += amountInAction;
  33.                 if (availableMoney >= moneyForVacantion) {
  34.                     System.out.printf("You saved the money for %d days.", counterDays);
  35.                     break;
  36.                 }
  37.             }
  38.  
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement