Advertisement
psi_mmobile

Untitled

May 21st, 2022
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         String city = scanner.nextLine();
  5.         double commission = Double.parseDouble(scanner.next());
  6.         double reduction = 500.0;
  7.         boolean isCityValid = true;
  8.         if (commission >= 0 && commission <= 500) {
  9.             switch (city) {
  10.                 case "Sofia" : reduction = 0.05; break;
  11.                 case "Varna" : reduction = 0.045; break;
  12.                 case "Plovdiv" : reduction = 0.055; break;
  13.                 default : reduction = reduction;isCityValid = false;
  14.             }
  15.         }
  16.         if (commission > 500 && commission <= 1000) {
  17.             switch (city) {
  18.                 case "Sofia" : reduction = 0.07;break;
  19.                 case "Varna" : reduction = 0.075;break;
  20.                 case "Plovdiv" : reduction = 0.08;break;
  21.                 default : reduction = reduction;isCityValid = false;
  22.             }
  23.         }
  24.         if (commission > 1000 && commission <= 10000) {
  25.             switch (city) {
  26.                 case "Sofia" : reduction = 0.08; break;
  27.                 case "Varna" : reduction = 0.1;break;
  28.                 case "Plovdiv" : reduction = 0.12;break;
  29.                 default : reduction = reduction;isCityValid = false;
  30.             }
  31.         }
  32.         if (commission > 10000) {
  33.             switch (city) {
  34.                 case "Sofia" : reduction = 0.12;break;
  35.                 case "Varna" : reduction = 0.13;break;
  36.                 case "Plovdiv" : reduction = 0.145;break;
  37.                 default : reduction = reduction;isCityValid = false;
  38.             }
  39.         }
  40.         if (reduction == 500 || !isCityValid) {
  41.             System.out.print("error");
  42.         } else {
  43.             System.out.printf("%.2f", commission * reduction);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement