Advertisement
finderabc

P04_Vacation

Nov 12th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_Vacation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double needMoneyForVocation = Double.parseDouble(scanner.nextLine());
  8.         double availableMoney = Double.parseDouble(scanner.nextLine());
  9.         int countAllDays = 0;
  10.         double saveMoney = availableMoney;
  11.         int countSpend = 0;
  12.  
  13.  
  14.         while (!(saveMoney >= needMoneyForVocation)){
  15.             countAllDays++;
  16.             String whatToDo = scanner.nextLine();
  17.             double money = Double.parseDouble(scanner.nextLine());
  18.             switch(whatToDo){
  19.                 case "spend":
  20.                     countSpend++;
  21.                     if(countSpend == 5){
  22.                         System.out.println("You can't save the money.");
  23.                         System.out.println(countAllDays);
  24.                         return;
  25.                     }
  26.                     if(money < saveMoney){
  27.                         saveMoney -= money;
  28.                     }else {
  29.                         saveMoney = 0;
  30.                     }
  31.                     break;
  32.                 case "save":
  33.                     countSpend = 0;
  34.                     saveMoney += money;
  35.                     break;
  36.             }
  37.         }
  38.         System.out.printf("You saved the money for %d days.", countAllDays);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement