Advertisement
desislava_topuzakova

06. Flower Shop

Nov 12th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. //1. входни данни
  7. int countMagnolias = Integer.parseInt(scanner.nextLine()); //брой на магнолиите
  8. int countHyacinths = Integer.parseInt(scanner.nextLine()); //брой на зюмбюлите
  9. int countRoses = Integer.parseInt(scanner.nextLine()); //брой на розите
  10. int countCacti = Integer.parseInt(scanner.nextLine()); //брой на кактусите
  11. double priceGift = Double.parseDouble(scanner.nextLine()); //цена на подарък, който трябва да купи
  12.  
  13. //2. обща сума = сума от магнолиите + сума от зюмбюлите + сума от рози + сума от кактуси
  14. double totalPrice = (countMagnolias * 3.25)
  15. + (countHyacinths * 4)
  16. + (countRoses * 3.50)
  17. + (countCacti * 8);
  18.  
  19. //3. данъци = 5% от обща сума
  20. double taxes = 0.05 * totalPrice;
  21.  
  22. //4. печалба = обща сума - данъци
  23. double profit = totalPrice - taxes;
  24.  
  25. //проверка дали е стигнала печалбата
  26. if (profit >= priceGift) {
  27. //достатъчна
  28. double leftMoney = profit - priceGift;
  29. System.out.printf("She is left with %.0f leva.", Math.floor(leftMoney));
  30. } else {
  31. //недостатъчна -> profit < priceGift
  32. double needMoney = priceGift - profit;
  33. System.out.printf("She will have to borrow %.0f leva.", Math.ceil(needMoney));
  34. }
  35.  
  36.  
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement