aneliabogeva

Vacation

Dec 13th, 2020
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.function.DoubleUnaryOperator;
  3.  
  4. public class Vacation {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         Double holidayMoney = Double.parseDouble(scanner.nextLine());
  8.         Double ownedMoney = Double.parseDouble(scanner.nextLine());
  9.         Integer counterSpend = 0;
  10.         Integer counter = 0;
  11.  
  12.         while(ownedMoney < holidayMoney){
  13.             String operation = scanner.nextLine();
  14.             Double amount = Double.parseDouble(scanner.nextLine());
  15.  
  16.             if("spend".equals(operation)){
  17.                 ownedMoney -= amount;
  18.                 counterSpend += 1;
  19.                 counter += 1;
  20.                 if(counterSpend >= 5){
  21.                     System.out.println("You can't save the money.");
  22.                     System.out.println(counter);
  23.                     break;
  24.                 }else {}
  25.                 if(ownedMoney < 0.00){
  26.                     ownedMoney = 0.00;
  27.                 }else {}
  28.             }else{
  29.                 ownedMoney += amount;
  30.                 counterSpend = 0;
  31.                 counter += 1;
  32.             }
  33.         }
  34.         if(ownedMoney >= holidayMoney){
  35.             System.out.printf("You saved the money for %d days.", counter);
  36.         }
  37.     }
  38. }
  39.  
RAW Paste Data