Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TradeCommissions {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. String city = scan.nextLine();
  7. double sells = Double.parseDouble(scan.nextLine());
  8. boolean other = city.equals("Sofia") || city.equals("Varna") || city.equals("Plovdiv");
  9. boolean other2 = sells < 0;
  10. double commission = sells * 1;
  11. switch (city) {
  12. case "Sofia":
  13. if (sells >= 0 && sells <= 500) {
  14. commission = sells * 0.05;
  15. } else if (sells > 500 && sells <= 1000) {
  16. commission = sells * 0.07;
  17. } else if (sells > 1000 && sells <= 10000) {
  18. commission = sells * 0.08;
  19. } else if (sells > 10000) {
  20. commission = sells * 0.12;
  21. }
  22. break;
  23. case "Varna":
  24. if (sells >= 0 && sells <= 500) {
  25. commission = sells * 0.045;
  26. } else if (sells > 500 && sells <= 1000) {
  27. commission = sells * 0.075;
  28. } else if (sells > 1000 && sells <= 10000) {
  29. commission = sells * 0.1;
  30. } else if (sells > 10000) {
  31. commission = sells * 0.13;
  32. }
  33. break;
  34. case "Plovdiv":
  35. if (sells >= 0 && sells <= 500) {
  36. commission = sells * 0.055;
  37. } else if (sells > 500 && sells <= 1000) {
  38. commission = sells * 0.08;
  39. } else if (sells > 1000 && sells <= 10000) {
  40. commission = sells * 0.12;
  41. } else if (sells > 10000) {
  42. commission = sells * 0.145;
  43. }
  44. break;
  45. }
  46. if (other && !other2) {
  47. System.out.printf("%.2f", commission);
  48. } else {
  49. System.out.println("error");
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement