Advertisement
GabrielHr00

07. Shopping

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