Advertisement
veronikaaa86

12. Trade Commissions

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