Advertisement
stoyanoff

Vacation_Zlatka

Jul 10th, 2020
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double moneyForExcursion = Double.parseDouble(scanner.nextLine());
  8.         double ownedMoney = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int daysCounter = 0;
  11.         int spendingCounter = 0;
  12.  
  13.         while (spendingCounter < 5) {
  14.             String command = scanner.nextLine();
  15.             double currentMoney = Double.parseDouble(scanner.nextLine());
  16.             daysCounter++;
  17.             if (command.equals("spend")) {
  18.                 spendingCounter++;
  19.                 ownedMoney -= currentMoney;
  20.                 if (ownedMoney < 0) {
  21.                     ownedMoney = 0;
  22.  
  23.                 }
  24.             } else if (command.equals("save")) {
  25.                 ownedMoney += currentMoney;
  26.                 spendingCounter = 0;
  27.  
  28.             }
  29.             if (ownedMoney >= moneyForExcursion) {
  30.                 System.out.printf("You saved the money for %d days.", daysCounter);
  31.                 break;
  32.             }
  33.  
  34.  
  35.         }
  36.         if (spendingCounter == 5) {
  37.             System.out.println("You can't save the money.");
  38.             System.out.println(daysCounter);
  39.         }
  40.  
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement