Advertisement
veronikaaa86

07. Shopping

Jan 16th, 2022
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package conditionalStatemnents;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07Shopping {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. double budget = Double.parseDouble(scanner.nextLine());
  10. int countVideoCards = Integer.parseInt(scanner.nextLine());
  11. int countCPU = Integer.parseInt(scanner.nextLine());
  12. int countRamMemory = Integer.parseInt(scanner.nextLine());
  13.  
  14. double sumVideoCards = countVideoCards * 250;
  15.  
  16. double priceCPU = 0.35 * sumVideoCards;
  17. double sumCPU = countCPU * priceCPU;
  18.  
  19. double priceRam = 0.1 * sumVideoCards;
  20. double sumRam = countRamMemory * priceRam;
  21.  
  22. double totalPrice = sumVideoCards + sumCPU + sumRam;
  23. if(countVideoCards > countCPU) {
  24. totalPrice = totalPrice - 0.15 * totalPrice;
  25. }
  26.  
  27. if(budget >= totalPrice) {
  28. double leftMoney = budget - totalPrice;
  29. System.out.printf("You have %.2f leva left!", leftMoney);
  30. } else {
  31. double needMoney = totalPrice - budget;
  32. System.out.printf("Not enough money! You need %.2f leva more!", needMoney);
  33. }
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement