Advertisement
Guest User

Vacation

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