Advertisement
veronikaaa86

12. Trade Commissions

Jan 21st, 2023
1,461
-1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 1
  1. package nestedConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P12TradeCommissions {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String town = scanner.nextLine();
  10.         double income = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double commission = 0;
  13.         if (town.equals("Sofia")) {
  14.             if (income >= 0 && income <= 500) {
  15.                 commission = income * 0.05;
  16.             } else if (income > 500 && income <= 1000) {
  17.                 commission = income * 0.07;
  18.             } else if (income > 1000 && income <= 10000) {
  19.                 commission = income * 0.08;
  20.             } else if (income > 10000) {
  21.                 commission = income * 0.12;
  22.             } else {
  23.                 System.out.println("error");
  24.             }
  25.         } else if (town.equals("Varna")) {
  26.             if (income >= 0 && income <= 500) {
  27.                 commission = income * 0.045;
  28.             } else if (income > 500 && income <= 1000) {
  29.                 commission = income * 0.075;
  30.             } else if (income > 1000 && income <= 10000) {
  31.                 commission = income * 0.10;
  32.             } else if (income > 10000) {
  33.                 commission = income * 0.13;
  34.             } else {
  35.                 System.out.println("error");
  36.             }
  37.         } else if (town.equals("Plovdiv")) {
  38.             if (income >= 0 && income <= 500) {
  39.                 commission = income * 0.055;
  40.             } else if (income > 500 && income <= 1000) {
  41.                 commission = income * 0.08;
  42.             } else if (income > 1000 && income <= 10000) {
  43.                 commission = income * 0.12;
  44.             } else if (income > 10000) {
  45.                 commission = income * 0.145;
  46.             } else {
  47.                 System.out.println("error");
  48.             }
  49.         } else {
  50.             System.out.println("error");
  51.         }
  52.  
  53.         if (commission > 0) {
  54.             System.out.printf("%.2f", commission);
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Comments
  • Hristian130
    1 year (edited)
    # text 0.52 KB | 0 0
    1. С вашият код излиза 94/100 ( ако се напише Plovdiv -20) Конзолата не дава никакви стойности
    2. Вместо
    3. else {
    4. System.out.println("error");
    5. }
    6.  
    7. if (commission > 0) {
    8. System.out.printf("%.2f", commission);
    9. }
    10. if (commission > 0 ) {
    11. System.out.printf("%.2f", commission);
    12. } else if (commission <= 0) {
    13. System.out.println("error");
    14. }
    15. Тогава judge ми даде 100/100
Add Comment
Please, Sign In to add comment
Advertisement