Guest User

Vacation

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