Advertisement
Sim0o0na

Untitled

Apr 16th, 2018
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package test10_03;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CellPhones {
  6.     public static void main(String[] agrs) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double budget = Double.parseDouble(scanner.nextLine());
  10.         int countPhones = Integer.parseInt(scanner.nextLine());
  11.         String mark = scanner.nextLine();
  12.  
  13.         int discount = 0;
  14.         double phonePrice = 0;
  15.         switch (mark) {
  16.             case "Gsm4e":
  17.                 discount += 1;
  18.                 phonePrice = 20.50;
  19.                 if (countPhones > 10 && countPhones <= 20) {
  20.                     discount += 2;
  21.                 } else if (countPhones > 20 && countPhones <= 50) {
  22.                     discount += 5;
  23.                 } else if (countPhones > 50) {
  24.                     discount += 7;
  25.                 }
  26.                 break;
  27.             case "Mobifon4e":
  28.                 discount += 2;
  29.                 phonePrice = 50.75;
  30.                 if (countPhones > 10 && countPhones <= 20) {
  31.                     discount += 2;
  32.                 } else if (countPhones > 20 && countPhones <= 50) {
  33.                     discount += 5;
  34.                 } else if (countPhones > 50) {
  35.                     discount += 7;
  36.                 }
  37.                 break;
  38.             case "Telefon4e":
  39.                 discount += 3;
  40.                 phonePrice = 115;
  41.                 if (countPhones > 10 && countPhones <= 20) {
  42.                     discount += 2;
  43.                 } else if (countPhones > 20 && countPhones <=50) {
  44.                     discount += 5;
  45.                 } else if (countPhones > 50) {
  46.                     discount += 7;
  47.                 }
  48.                 break;
  49.         }
  50.         double price = countPhones * phonePrice;
  51.         double discountPrice = price - (discount * price) / 100;
  52.  
  53.         if (budget >= discountPrice) {
  54.             System.out.printf("The company bought all mobile phones. %.2f leva left.", budget - discountPrice);
  55.         } else {
  56.             System.out.printf("Not enough money for all mobiles. Company needs %.2f more leva.", discountPrice - budget);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement