finderabc

Cellphones

Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package ExamLevel3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Cellphones {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.         int budget = Integer.parseInt(console.nextLine());
  9.         int countPhone = Integer.parseInt(console.nextLine());
  10.         String brand = console.nextLine();
  11.        
  12.         double price = 0.00;
  13.         double discount = 0.00;
  14.        
  15.  
  16.         if (countPhone > 10 && countPhone <= 20) {
  17.             discount += 0.02;
  18.         } else if (countPhone > 20 && countPhone <= 50) {
  19.             discount += 0.05;
  20.         } else if (countPhone > 50) {
  21.             discount += 0.07;
  22.         }
  23.         switch (brand) {
  24.             case "Gsm4e":
  25.                 discount +=0.01;
  26.                 price = 20.50 -  20.50 * discount;
  27.                 break;
  28.             case "Mobifon4e":
  29.                 discount +=0.02;
  30.                 price = 50.75 -  50.75 * discount;
  31.                 break;
  32.             case "Telefon4e":
  33.                 discount +=0.03;
  34.                 price =   115 -  115 * discount;
  35.                 break;
  36.  
  37.         }
  38.      double totalPrice = price*countPhone;
  39.  
  40.         if (budget >= totalPrice) {
  41.             System.out.printf("The company bought all mobile phones. %.2f leva left.", budget - totalPrice);
  42.         } else {
  43.             System.out.printf("Not enough money for all mobiles. Company needs %.2f more leva.", totalPrice - budget);
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment