Advertisement
Guest User

Untitled

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