myrdok123

07. Shopping

Apr 30th, 2023
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package L02_ConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07_Shopping {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         double budget = Double.parseDouble(scanner.nextLine());
  11.         int countVideoCard = Integer.parseInt(scanner.nextLine());
  12.         int countProcessor = Integer.parseInt(scanner.nextLine());
  13.         int countRam = Integer.parseInt(scanner.nextLine());
  14.  
  15.         double priceVideoCard = countVideoCard * 250;
  16.         double priceProcessors = countProcessor * (priceVideoCard * 0.35);
  17.         double priceRam = countRam * (priceVideoCard * 0.10);
  18.  
  19.         double finalSum = priceVideoCard + priceProcessors + priceRam;
  20.  
  21.         if(countVideoCard > countProcessor){
  22.             finalSum = finalSum * 0.85; // finalSum - finalSum * 0.15
  23.         }
  24.  
  25.         double diff = Math.abs(finalSum - budget);
  26.  
  27.         if(budget >= finalSum){
  28.             System.out.printf("You have %.2f leva left!", diff);
  29.         }else {
  30.             System.out.printf("Not enough money! You need %.2f leva more!", diff);
  31.         }
  32.  
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment