myrdok123

04. Toy Shop

Apr 30th, 2023
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package L02_ConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04_ToyShop {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11.         // Прочитаме входните данни
  12.         // Пресмятаме броя на играчките
  13.         // Пресмятаме общата сума за всички играчки
  14.         // Проверяваме дали играчките са 50 или повече -> имаме 25% отстъпка
  15.         // Пресмятаме колко пари са ни останали след като платим наема -> 10% от общата сума
  16.         // Проверка дали парите са достатъчни
  17.  
  18.         double tripPrice = Double.parseDouble(scanner.nextLine());
  19.         int puzzlesCount = Integer.parseInt(scanner.nextLine());
  20.         int dollsCount = Integer.parseInt(scanner.nextLine());
  21.         int teddyBearsCount = Integer.parseInt(scanner.nextLine());
  22.         int minionsCount = Integer.parseInt(scanner.nextLine());
  23.         int truckCount = Integer.parseInt(scanner.nextLine());
  24.  
  25.  
  26.         /*•   Пъзел - 2.60 лв.
  27. • Говореща кукла - 3 лв.
  28. • Плюшено мече - 4.10 лв.
  29. • Миньон - 8.20 лв.
  30. • Камионче - 2 лв.*/
  31.  
  32.         int countToys = puzzlesCount + dollsCount + teddyBearsCount + minionsCount +truckCount;
  33.         double totalSum = puzzlesCount * 2.60 + dollsCount * 3 + teddyBearsCount * 4.10 + minionsCount * 8.20 + truckCount * 2;
  34.  
  35.         if (countToys >= 50){
  36.             totalSum = totalSum * 0.75; //totalSum - totalSum * 0.25
  37.         }
  38.  
  39.         totalSum = totalSum * 0.9;// totalSum - totalSum * 0.1
  40.  
  41.         if (totalSum >= tripPrice){
  42.             double restMoney = totalSum - tripPrice;
  43.             System.out.printf("Yes! %.2f lv left.", restMoney);
  44.         } else {
  45.             double neededMoney = tripPrice - totalSum;
  46.  
  47.             System.out.printf("Not enough money! %.2f lv needed.", neededMoney);
  48.         }
  49.  
  50.  
  51.  
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment