Advertisement
veronikaaa86

12. Trade Commissions

May 21st, 2022
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  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. boolean isValidData = true;
  13.  
  14. double result = 0;
  15. if (town.equals("Sofia")) {
  16. if (income >= 0 && income <= 500) {
  17. result = income * 0.05;
  18. } else if (income > 500 && income <= 1000) {
  19. result = income * 0.07;
  20. } else if (income > 1000 && income <= 10000) {
  21. result = income * 0.08;
  22. } else if (income > 10000) {
  23. result = income * 0.12;
  24. } else {
  25. isValidData = false;
  26. }
  27. } else if (town.equals("Varna")) {
  28. if (income >= 0 && income <= 500) {
  29. result = income * 0.045;
  30. } else if (income > 500 && income <= 1000) {
  31. result = income * 0.075;
  32. } else if (income > 1000 && income <= 10000) {
  33. result = income * 0.10;
  34. } else if (income > 10000) {
  35. result = income * 0.13;
  36. } else {
  37. isValidData = false;
  38. }
  39. } else if (town.equals("Plovdiv")) {
  40. if (income >= 0 && income <= 500) {
  41. result = income * 0.055;
  42. } else if (income > 500 && income <= 1000) {
  43. result = income * 0.08;
  44. } else if (income > 1000 && income <= 10000) {
  45. result = income * 0.12;
  46. } else if (income > 10000) {
  47. result = income * 0.145;
  48. } else {
  49. isValidData = false;
  50. }
  51. } else {
  52. isValidData = false;
  53. }
  54.  
  55. if (isValidData) {
  56. System.out.printf("%.2f", result);
  57. } else {
  58. System.out.println("error");
  59. }
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement