Guest User

Vacation #java

a guest
Sep 24th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class proba {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double moneyNeeded = Double.parseDouble(scanner.nextLine());
  8.         double moneyAvailable = Double.parseDouble(scanner.nextLine());
  9.         int days = 0;
  10.         int daysSpending = 0;
  11.         boolean taqHarchiMn=false;
  12.  
  13.         while (moneyAvailable < moneyNeeded){
  14.             String action = scanner.nextLine();
  15.             double amount = Double.parseDouble(scanner.nextLine());
  16.             days++;
  17.  
  18.             if (action.equals("save")){
  19.                 moneyAvailable += amount;
  20.             }else {
  21.                 daysSpending++;
  22.                 moneyAvailable -= amount;
  23.  
  24.                 if ( moneyAvailable <= 0 ){
  25.                     moneyAvailable = 0;
  26.                 }
  27.  
  28.                 if (daysSpending == 5){
  29.                     System.out.printf("You can't save the money.\n" +
  30.                             "%d\n",daysSpending);
  31.                     taqHarchiMn = true;
  32.                     break;
  33.                 }
  34.  
  35.             }
  36.  
  37.         }
  38.         if (!taqHarchiMn){
  39.             System.out.printf("You saved the money for %d days.",days);
  40.         }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment