Advertisement
veronikaaa86

04. Toy Shop

Nov 7th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package conditionalStatemnents;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04ToyShop {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. double tripPrice = Double.parseDouble(scanner.nextLine());
  10. int puzzleCount = Integer.parseInt(scanner.nextLine());
  11. int dollsCount = Integer.parseInt(scanner.nextLine());
  12. int teddyCount = Integer.parseInt(scanner.nextLine());
  13. int minionsCount = Integer.parseInt(scanner.nextLine());
  14. int trucksCount = Integer.parseInt(scanner.nextLine());
  15.  
  16. // • Пъзел - 2.60 лв.
  17. // • Говореща кукла - 3 лв.
  18. // • Плюшено мече - 4.10 лв.
  19. // • Миньон - 8.20 лв.
  20. // • Камионче - 2 лв.
  21.  
  22. double allSum = (puzzleCount * 2.60) +
  23. (dollsCount * 3.0) +
  24. (teddyCount * 4.10) +
  25. (minionsCount * 8.20) +
  26. (trucksCount * 2.0);
  27.  
  28. int countAllToys = puzzleCount + dollsCount + teddyCount + minionsCount + trucksCount;
  29.  
  30. if (countAllToys >= 50) {
  31. allSum = allSum * 0.75;
  32. }
  33.  
  34. allSum = allSum * 0.90;
  35.  
  36. double diff = Math.abs(allSum - tripPrice); // 50 - 100 = -50
  37. if (allSum >= tripPrice) {
  38. System.out.printf("Yes! %.2f lv left.", diff);
  39. } else {
  40. System.out.printf("Not enough money! %.2f lv needed.", diff);
  41. }
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement