Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test10_03;
- import java.util.Scanner;
- public class CellPhones {
- public static void main(String[] agrs) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- int countPhones = Integer.parseInt(scanner.nextLine());
- String mark = scanner.nextLine();
- int discount = 0;
- double phonePrice = 0;
- switch (mark) {
- case "Gsm4e":
- discount += 1;
- phonePrice = 20.50;
- if (countPhones > 10 && countPhones <= 20) {
- discount += 2;
- } else if (countPhones > 20 && countPhones <= 50) {
- discount += 5;
- } else if (countPhones > 50) {
- discount += 7;
- }
- break;
- case "Mobifon4e":
- discount += 2;
- phonePrice = 50.75;
- if (countPhones > 10 && countPhones <= 20) {
- discount += 2;
- } else if (countPhones > 20 && countPhones <= 50) {
- discount += 5;
- } else if (countPhones > 50) {
- discount += 7;
- }
- break;
- case "Telefon4e":
- discount += 3;
- phonePrice = 115;
- if (countPhones > 10 && countPhones <= 20) {
- discount += 2;
- } else if (countPhones > 20 && countPhones <=50) {
- discount += 5;
- } else if (countPhones > 50) {
- discount += 7;
- }
- break;
- }
- double price = countPhones * phonePrice;
- double discountPrice = price - (discount * price) / 100;
- if (budget >= discountPrice) {
- System.out.printf("The company bought all mobile phones. %.2f leva left.", budget - discountPrice);
- } else {
- System.out.printf("Not enough money for all mobiles. Company needs %.2f more leva.", discountPrice - budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement