Advertisement
Deiancom

Vacation

Jun 30th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Vacation {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         double moneyNeededForExcursion = Double.parseDouble(scanner.nextLine());
  9.         double moneyHave = Double.parseDouble(scanner.nextLine());
  10.         int countSpendDays = 0;
  11.         int countDays = 0;
  12.         while (!(moneyNeededForExcursion <= moneyHave)) {
  13.             String input = scanner.nextLine();
  14.             double money = Double.parseDouble(scanner.nextLine());
  15.             countDays++;
  16.             if (input.equals("save")) {
  17.                 moneyHave += money;
  18.                 countSpendDays = 0;
  19.  
  20.             }else if (input.equals("spend")) {
  21.                 countSpendDays++;
  22.                 if (moneyHave < money) {
  23.                     moneyHave = 0;
  24.                 }else {
  25.                     moneyHave -= money;
  26.                 }
  27.             }
  28.         }
  29.         if (moneyHave >= moneyNeededForExcursion) {
  30.             System.out.printf("You saved the money for %d days.",countDays);
  31.         }else if (countSpendDays >= 5) {
  32.             System.out.printf("You can't save the money.%n%d", countDays);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement