Advertisement
Guest User

Untitled

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