Квартално магазинче Java
Преписано от учебника 1:1 в IntelliJ и гърми. Обяснение защо? Някой ?
import java.util.Scanner; public class Shop { public static void main(String[] args) { Scanner input = new Scanner(System.in); String town = input.nextLine().toLowerCase(); String product = input.nextLine().toLowerCase(); double quantity = Double.parseDouble(input.nextLine()); double price = 0; if (town.equals("Sofia")) { if (product.equals("coffee")) { price = 0.8 * quantity; } else if (product.equals("water")) { price = 0.7 * quantity; } else if (product.equals("beer")) { price = 1.2 * quantity; } else if (product.equals("sweets")) { price = 1.45 * quantity; } else if (product.equals("peanuts")) { price = 1.6 * quantity; } } else if (town.equals("Plovdiv")) { if (product.equals("coffee")) { price = 0.8 * quantity; } else if (product.equals("water")) { price = 0.7 * quantity; } else if (product.equals("beer")) { price = 1.2 * quantity; } else if (product.equals("sweets")) { price = 1.45 * quantity; } else if (product.equals("peanuts")) { price = 1.6 * quantity; } else if (town.equals("Varna")) { if (product.equals("coffee")) { price = 0.8 * quantity; } else if (product.equals("water")) { price = 0.7 * quantity; } else if (product.equals("beer")) { price = 1.2 * quantity; } else if (product.equals("sweets")) { price = 1.45 * quantity; } else if (product.equals("peanuts")) { price = 1.6 * quantity; } } } System.out.println(price); } }
Под гърми, имам предвид, че ми дава 0 като резултат.