desislava_topuzakova

05. Small Shop

Sep 25th, 2021
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SmallShop_05 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String product = scanner.nextLine();
  8. String town = scanner.nextLine(); //Sofia, Varna, Plovdiv
  9. double quantity = Double.parseDouble(scanner.nextLine());
  10.  
  11.  
  12. double price = 0; //единична цена
  13.  
  14. //проверка за градовете
  15. switch(town) {
  16. case "Sofia":
  17. //проверка за продукт -> coffee water beer sweets peanuts
  18. if (product.equals("coffee")) {
  19. price = 0.50;
  20. } else if (product.equals("water")) {
  21. price = 0.80;
  22. } else if (product.equals("beer")) {
  23. price = 1.20;
  24. } else if (product.equals("sweets")) {
  25. price = 1.45;
  26. } else if (product.equals("peanuts")) {
  27. price = 1.60;
  28. }
  29. break;
  30. case "Varna":
  31. //проверка за продукт -> coffee water beer sweets peanuts
  32. if (product.equals("coffee")) {
  33. price = 0.45;
  34. } else if (product.equals("water")) {
  35. price = 0.70;
  36. } else if (product.equals("beer")) {
  37. price = 1.10;
  38. } else if (product.equals("sweets")) {
  39. price = 1.35;
  40. } else if (product.equals("peanuts")) {
  41. price = 1.55;
  42. }
  43. break;
  44. case "Plovdiv":
  45. //проверка за продукт -> coffee water beer sweets peanuts
  46. if (product.equals("coffee")) {
  47. price = 0.40;
  48. } else if (product.equals("water")) {
  49. price = 0.70;
  50. } else if (product.equals("beer")) {
  51. price = 1.15;
  52. } else if (product.equals("sweets")) {
  53. price = 1.30;
  54. } else if (product.equals("peanuts")) {
  55. price = 1.50;
  56. }
  57. break;
  58. }
  59.  
  60. //единичната цена за закупения продукт
  61. //крайна цена = количество * ед. цена (град и продукт)
  62. double totalPrice = quantity * price;
  63. System.out.println(totalPrice);
  64.  
  65.  
  66. }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment