Advertisement
Valantina

Shopping/Ex/Java

Jul 9th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P02_Shopping {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double peterBudget = Double.parseDouble(scan.nextLine());
  8.         int videoCardsCount = Integer.parseInt(scan.nextLine());
  9.         int processorsCount = Integer.parseInt(scan.nextLine());
  10.         int ramCount = Integer.parseInt(scan.nextLine());
  11.  
  12.         double totalPriceForVideoCards = videoCardsCount * 250;
  13.         double totalPriceForProcessors = processorsCount * (totalPriceForVideoCards * 0.35);
  14.         double totalPriceForRam = ramCount * (totalPriceForVideoCards * 0.1);
  15.  
  16.         double totalPrice = totalPriceForVideoCards + totalPriceForProcessors + totalPriceForRam;
  17.         double discount = 0;
  18.  
  19.         if (videoCardsCount > processorsCount) {
  20.             discount = totalPrice * 0.15;
  21.             totalPrice -= discount;
  22.         }
  23.  
  24.         double moneyLeft = peterBudget - totalPrice;
  25.  
  26.         if (totalPrice <= peterBudget) {
  27.             System.out.println(String.format("You have %.2f leva left!", moneyLeft));
  28.         } else {
  29.             moneyLeft = totalPrice - peterBudget;
  30.             System.out.println(String.format("Not enough money! You need %.2f leva more!", moneyLeft));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement