Denis2312

Ex7Shopping

Jan 16th, 2023 (edited)
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package ConditionalStatements;
  2. import java.util.Scanner;
  3. public class Ex7Shopping {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         int countVideoCards = Integer.parseInt(scanner.nextLine());
  9.         int countCPU = Integer.parseInt(scanner.nextLine());  //процесор
  10.         int countRAM = Integer.parseInt(scanner.nextLine());  //памет
  11.  
  12.         double sumVideoCards = countVideoCards * 250;
  13.         double sumCPU = (sumVideoCards * 0.35) * countCPU;
  14.         double ramPrice = (sumVideoCards * 0.1) * countRAM;
  15.         double totalSum = sumVideoCards + sumCPU + ramPrice;
  16.  
  17.         if(countVideoCards > countCPU){
  18.             totalSum = totalSum - totalSum * 0.15;
  19.         }
  20.         double moneyLeft = budget - totalSum;
  21.         double moneyNeeded = totalSum - budget;
  22.  
  23.         if(budget >= totalSum){
  24.             System.out.printf("You have %.2f leva left!", moneyLeft);
  25.         }
  26.         else{
  27.             System.out.printf("Not enough money! You need %.2f leva more!", moneyNeeded);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment