Advertisement
Guest User

Vacation

a guest
Sep 17th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. Scanner scanner = new Scanner(System.in);                    // 77/100 ???
  2.         double moneyNeeded = Double.parseDouble(scanner.nextLine());
  3.         double moneyHas = Double.parseDouble(scanner.nextLine());
  4.  
  5.         int totalDays = 0;
  6.         int spentDays = 0;
  7.  
  8.         while (moneyHas < moneyNeeded && spentDays < 5) {  
  9.             String saveOrSpend = scanner.nextLine();
  10.             double sumSaveSpend = Double.parseDouble(scanner.nextLine());
  11.             totalDays++;
  12.  
  13.             if (saveOrSpend.equals("spend")) {
  14.                 moneyHas -= sumSaveSpend;
  15.                 spentDays++;
  16.                 if (moneyHas <= 0) {
  17.                     moneyHas = 0;
  18.                 }
  19.  
  20.             } else if (saveOrSpend.equals("save")) {
  21.                 moneyHas += sumSaveSpend;
  22.                 spentDays = 0;                  //•   Ако 5 последователни дни Джеси само харчи !!!
  23.             }
  24.         }
  25.         if (moneyHas >= moneyNeeded) {
  26.             System.out.printf("You saved the money for %d days.", totalDays);
  27.         }
  28.         if (spentDays == 5) {              //•    Ако 5 последователни дни Джеси само харчи
  29.             System.out.println("You can't save the money.");
  30.             System.out.println(spentDays);
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement