Advertisement
Spocoman

07. Shopping

Aug 24th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Shopping {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget = Double.parseDouble(scanner.nextLine());
  7.         int gpu = Integer.parseInt(scanner.nextLine());
  8.         int cpu = Integer.parseInt(scanner.nextLine());
  9.         int ram = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int gpuPrice = gpu * 250;
  12.         double cpuPrice = cpu * gpuPrice * 0.35;
  13.         double ramPrice = ram * gpuPrice * 0.10;
  14.  
  15.         double totalAmount = gpuPrice + cpuPrice + ramPrice;
  16.  
  17.         if (gpu > cpu) {
  18.             totalAmount *= 0.85;
  19.         }
  20.         if (budget >= totalAmount) {
  21.             System.out.printf("You have %.2f leva left!", budget - totalAmount);
  22.         } else {
  23.             System.out.printf("Not enough money! You need %.2f leva more!", totalAmount - budget);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement