Advertisement
EliPerfanova

Vacation

Oct 11th, 2019
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 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 moneyNeeded = Double.parseDouble(scanner.nextLine());
  8.         double money = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int spendDays = 0;
  11.         int days = 0;
  12.  
  13.         while (money < moneyNeeded) {
  14.             String status = scanner.nextLine();
  15.             double sum = Double.parseDouble(scanner.nextLine());
  16.  
  17.             if (status.equals("spend")) {
  18.                 money -= sum;
  19.                 if (money < 0) {
  20.                     money = 0;
  21.                 }
  22.  
  23.                 spendDays++;
  24.             }else if (status.equals("save")) {
  25.                 money += sum;
  26.                 spendDays = 0;
  27.             }
  28.             days++;
  29.             if (spendDays == 5) {
  30.                 System.out.printf("You can't save the money.%n%d",days);
  31.  
  32.                 break;
  33.             }}
  34.         if (money >= moneyNeeded) {
  35.             System.out.printf("You saved the money for %s days.", days);
  36.         }
  37.  
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement