Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExamLevel3;
- import java.util.Scanner;
- public class Cellphones {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- int budget = Integer.parseInt(console.nextLine());
- int countPhone = Integer.parseInt(console.nextLine());
- String brand = console.nextLine();
- double price = 0.00;
- double discount = 0.00;
- if (countPhone > 10 && countPhone <= 20) {
- discount += 0.02;
- } else if (countPhone > 20 && countPhone <= 50) {
- discount += 0.05;
- } else if (countPhone > 50) {
- discount += 0.07;
- }
- switch (brand) {
- case "Gsm4e":
- discount +=0.01;
- price = 20.50 - 20.50 * discount;
- break;
- case "Mobifon4e":
- discount +=0.02;
- price = 50.75 - 50.75 * discount;
- break;
- case "Telefon4e":
- discount +=0.03;
- price = 115 - 115 * discount;
- break;
- }
- double totalPrice = price*countPhone;
- if (budget >= totalPrice) {
- System.out.printf("The company bought all mobile phones. %.2f leva left.", budget - totalPrice);
- } else {
- System.out.printf("Not enough money for all mobiles. Company needs %.2f more leva.", totalPrice - budget);
- }
- }
- }
Add Comment
Please, Sign In to add comment