Kancho

Holidays_Money

Feb 7th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Holidays_Money {
  4. public static void main(String[] args) {
  5.  
  6. Scanner keyboard = new Scanner(System.in);
  7. System.out.print("Necessary money: ");
  8. double necessaryMoney = Double.parseDouble(keyboard.nextLine());
  9. System.out.print("Available money: ");
  10. double moneyAvailable = Double.parseDouble(keyboard.nextLine());
  11. int countAllDays = 0;
  12. int countSpendDays = 0;
  13.  
  14. while (moneyAvailable <= necessaryMoney) {
  15. countAllDays++;
  16. System.out.print("Save or spend: ");
  17. String action = keyboard.nextLine();
  18. if (action.equalsIgnoreCase("save")) {
  19. System.out.println("How mush do you save: ");
  20. double savedMoney = Double.parseDouble(keyboard.nextLine());
  21. moneyAvailable = moneyAvailable + savedMoney;
  22. // System.out.println("You have " + moneyAvailable);
  23.  
  24. }
  25. if (action.equalsIgnoreCase("spend")) {
  26. countSpendDays++;
  27. System.out.println("How much do you wanna spend: ");
  28. double spentMoney = Double.parseDouble(keyboard.nextLine());
  29. moneyAvailable -= spentMoney;
  30.  
  31. } if (moneyAvailable < 0) {
  32. moneyAvailable = 0;
  33. System.out.println("You have " + moneyAvailable);
  34. }if (countSpendDays == 5) {
  35. System.out.printf("Yoy cannot save the necessary %.2f lv. %d days passed.%n",necessaryMoney,countSpendDays);
  36. System.out.println("You have " + moneyAvailable + "lv.");
  37. break;
  38. }
  39.  
  40. System.out.println("You have " + moneyAvailable + "lv.");
  41.  
  42. }
  43. if (moneyAvailable >= necessaryMoney) {
  44. System.out.printf("You saved the necessary %.2f lv. for %d days.", necessaryMoney, countAllDays);
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment