Lyubohd

02. Shopping

Oct 24th, 2020
469
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         // Вход
  7.         double peterBudget = Double.parseDouble(scan.nextLine());
  8.         int videCardCount = Integer.parseInt(scan.nextLine());
  9.         int processorCount = Integer.parseInt(scan.nextLine());
  10.         int ramCount = Integer.parseInt(scan.nextLine());
  11.  
  12.         // Video Card
  13.         int videoCardsTotalPrice = videCardCount * 250;
  14.  
  15.         // Processor
  16.         double processorPrice = videoCardsTotalPrice * 0.35;
  17.         double processorTotalPrice = processorCount * processorPrice;
  18.  
  19.         // Ram
  20.         double ramPrice = videoCardsTotalPrice * 0.10;
  21.         double ramTotalPrice = ramCount * ramPrice;
  22.  
  23.         double totalPrice = videoCardsTotalPrice + processorTotalPrice + ramTotalPrice;
  24.         if (videCardCount > processorCount) {
  25.             totalPrice = totalPrice * 0.85;
  26.         }
  27.  
  28.         if (peterBudget >= totalPrice) {
  29.             double moneyLeft = peterBudget - totalPrice;
  30.             System.out.printf("You have %.2f leva left!", moneyLeft);
  31.         } else {
  32.             double moneyNeed = totalPrice - peterBudget;
  33.             System.out.printf("Not enough money! You need %.2f leva more!", moneyNeed);
  34.         }
  35.     }
  36. }
RAW Paste Data