galinyotsev123

ProgBasics04Nested-Statements-P02SmallShop

Jan 5th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P02SmallShop {
  4. public static void main(String[] Arg) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double CoffeeSofia = 0.50;
  8. double CoffeePlovdiv = 0.40;
  9. double CoffeeVarna = 0.45;
  10.  
  11. double WaterSofia = 0.80;
  12. double WaterPlovdiv = 0.70;
  13. double WaterVarna = 0.70;
  14.  
  15. double BeerSofia = 1.20;
  16. double BeerPlovdiv = 1.15;
  17. double BeerVarna = 1.10;
  18.  
  19. double SweetsSofia = 1.45;
  20. double SweetsPlovdiv = 1.30;
  21. double SweetsVarna = 1.35;
  22. double PeanutsSofia = 1.60;
  23. double PeanutsPlovdiv = 1.50;
  24. double PeanutsVarna = 1.55;
  25.  
  26. String product = scanner.nextLine();
  27. String city = scanner.nextLine();
  28. double quantity = Double.parseDouble(scanner.nextLine());
  29. double Totalprice = 0;
  30.  
  31. if (city.equalsIgnoreCase("Sofia")) {
  32. if (product.equalsIgnoreCase("Coffee")) {
  33. Totalprice = CoffeeSofia * quantity;
  34. } else if (product.equalsIgnoreCase("Water")) {
  35. Totalprice = WaterSofia * quantity;
  36. } else if (product.equalsIgnoreCase("Beer")) {
  37. Totalprice = BeerSofia * quantity;
  38. } else if (product.equalsIgnoreCase("Sweets")) {
  39. Totalprice = SweetsSofia * quantity;
  40. } else if (product.equalsIgnoreCase("Peanuts")) {
  41. Totalprice = PeanutsSofia * quantity;
  42. }
  43. } else if (city.equalsIgnoreCase("Plovdiv")) {
  44. if (product.equalsIgnoreCase("Coffee")) {
  45. Totalprice = CoffeePlovdiv * quantity;
  46. } else if (product.equalsIgnoreCase("Water")) {
  47. Totalprice = WaterPlovdiv * quantity;
  48. } else if (product.equalsIgnoreCase("Beer")) {
  49. Totalprice = BeerPlovdiv * quantity;
  50. } else if (product.equalsIgnoreCase("Sweets")) {
  51. Totalprice = SweetsPlovdiv * quantity;
  52. } else if (product.equalsIgnoreCase("Peanuts")) {
  53. Totalprice = PeanutsPlovdiv * quantity;
  54. }
  55. } else if (city.equalsIgnoreCase("Varna")) {
  56. if (product.equalsIgnoreCase("Coffee")) {
  57. Totalprice = CoffeeVarna * quantity;
  58. } else if (product.equalsIgnoreCase("Water")) {
  59. Totalprice = WaterVarna * quantity;
  60. } else if (product.equalsIgnoreCase("Beer")) {
  61. Totalprice = BeerVarna * quantity;
  62. } else if (product.equalsIgnoreCase("Sweets")) {
  63. Totalprice = SweetsVarna * quantity;
  64. } else if (product.equalsIgnoreCase("Peanuts")) {
  65. Totalprice = PeanutsVarna * quantity;
  66. }
  67. }
  68. System.out.println(Totalprice);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment