desislava_topuzakova

Untitled

May 8th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String city = scanner.nextLine();
  8. double quantity = Double.parseDouble(scanner.nextLine());
  9.  
  10. double percent = 0;
  11. if ("Sofia".equals(city)){
  12. if (quantity >= 0 && quantity <= 500){
  13. percent = 5;
  14. } else if (quantity > 500 && quantity <= 1000){
  15. percent = 7;
  16. } else if(quantity > 1000 && quantity <= 10000){
  17. percent = 8;
  18. } else if (quantity > 10000){
  19. percent = 12;
  20. }
  21. } else if ("Varna".equals(city)){
  22. if (quantity >= 0 && quantity <= 500){
  23. percent = 4.5;
  24. } else if (quantity > 500 && quantity <= 1000){
  25. percent = 7.5;
  26. } else if(quantity > 1000 && quantity <= 10000){
  27. percent = 10;
  28. } else if (quantity > 10000){
  29. percent = 13;
  30. }
  31. } else if ("Plovdiv".equals(city)){
  32. if (quantity >= 0 && quantity <= 500){
  33. percent = 5.5;
  34. } else if (quantity > 500 && quantity <= 1000){
  35. percent = 8;
  36. } else if(quantity > 1000 && quantity <= 10000){
  37. percent = 12;
  38. } else {
  39. percent = 14.5;
  40. }
  41. }
  42.  
  43. if (quantity >= 0 &&
  44. ("Sofia".equals(city) || "Varna".equals(city) || "Plovdiv".equals(city))) {
  45. double result = quantity * (percent / 100);
  46. System.out.printf("%.2f", result);
  47. } else {
  48. System.out.println("error");
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment