Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TradeCommissions {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String town = scanner.nextLine();
- double profit = Double.parseDouble(scanner.nextLine());
- double commission = 0;
- if (town.equals("Sofia")) {
- if (profit > 0 && profit <= 500) {
- commission = 0.05;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.07;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.08;
- } else if (profit > 10000) {
- commission = 0.12;
- }
- } else if (town.equals("Varna")) {
- if (profit > 0 && profit <= 500) {
- commission = 0.045;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.075;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.1;
- } else if (profit > 10000) {
- commission = 0.13;
- }
- } else if (town.equals("Plovdiv")) {
- if (profit > 0 && profit <= 500) {
- commission = 0.055;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.08;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.12;
- } else if (profit > 10000) {
- commission = 0.145;
- }
- }
- double sum = profit * commission;
- if (sum > 0) {
- System.out.printf("%.2f\n", sum);
- } else {
- System.out.println("error");
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class TradeCommissions {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String town = scanner.nextLine();
- double profit = Double.parseDouble(scanner.nextLine());
- double commission = 0;
- switch (town) {
- case "Sofia" -> {
- if (profit > 0 && profit <= 500) {
- commission = 0.05;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.07;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.08;
- } else if (profit > 10000) {
- commission = 0.12;
- }
- }
- case "Varna" -> {
- if (profit > 0 && profit <= 500) {
- commission = 0.045;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.075;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.1;
- } else if (profit > 10000) {
- commission = 0.13;
- }
- }
- case "Plovdiv" -> {
- if (profit > 0 && profit <= 500) {
- commission = 0.055;
- } else if (profit > 500 && profit <= 1000) {
- commission = 0.08;
- } else if (profit > 1000 && profit <= 10000) {
- commission = 0.12;
- } else if (profit > 10000) {
- commission = 0.145;
- }
- }
- }
- double sum = profit * commission;
- if (sum > 0) {
- System.out.printf("%.2f\n", sum);
- } else {
- System.out.println("error");
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String town = scanner.nextLine();
- double profit = Double.parseDouble(scanner.nextLine());
- double commission =
- town.equals("Sofia") ?
- (profit > 0 && profit <= 500 ? 0.05 : profit > 500 && profit <= 1000 ? 0.07 : profit > 1000 && profit <= 10000 ? 0.08 : profit > 10000 ? 0.12 : 0) :
- town.equals("Varna") ?
- (profit > 0 && profit <= 500 ? 0.045 : profit > 500 && profit <= 1000 ? 0.075 : profit > 1000 && profit <= 10000 ? 0.1 : profit > 10000 ? 0.13 : 0) :
- town.equals("Plovdiv") ?
- (profit > 0 && profit <= 500 ? 0.055 : profit > 500 && profit <= 1000 ? 0.08 : profit > 1000 && profit <= 10000 ? 0.12 : profit > 10000 ? 0.145 : 0) : 0;
- double sum = profit * commission;
- System.out.printf(sum == 0 ? "error\n" : "%.2f\n", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement