Advertisement
AngelKejov

Vacantion

Apr 15th, 2021
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Vacation {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         double neededMoney = Double.parseDouble(sc.nextLine());
  11.         double hisMoney = Double.parseDouble(sc.nextLine());
  12.  
  13.         int totalDays = 0;
  14.         int daysSpend = 0;
  15.         while (hisMoney < neededMoney &&  daysSpend < 5) {
  16.             String input = sc.nextLine();
  17.             double money = Double.parseDouble(sc.nextLine());
  18.             totalDays++;
  19.  
  20.             if (input.equals("spend")) {
  21.                 daysSpend++;
  22.                 hisMoney -= money;
  23.                 if (hisMoney < 0) {
  24.                     hisMoney = 0;
  25.                 }
  26.             } else if (input.equals("save")) {
  27.                 daysSpend = 0;
  28.                 hisMoney += money;
  29.             }
  30.         }
  31.         if (daysSpend == 5) {
  32.             System.out.println("You can't save the money.");
  33.             System.out.println(daysSpend);
  34.         }
  35.  
  36.         if (hisMoney >= neededMoney) {
  37.             System.out.printf("You saved the money for %d days.", totalDays);
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement