Advertisement
deyanivanov966

03. Vacation

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