Advertisement
Guest User

Untitled

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