Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class temp_Advanced {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- Map<String, Map<String, Double>> shops = new TreeMap<>();
- while (!input.equals("Revision")) {
- String[] tokens = input.split(", ");
- String shopName = tokens[0];
- String product = tokens[1];
- double price = Double.parseDouble(tokens[2]);
- Map<String, Double> priceList = shops.get(shopName);
- if (!shops.containsKey(shopName)) {
- priceList = new LinkedHashMap<>();
- priceList.put(product, price);
- shops.put(shopName, priceList);
- } else {
- shops.get(shopName).put(product, price);
- }
- input = scanner.nextLine();
- }
- for (Map.Entry<String, Map<String, Double>> entry : shops.entrySet()) {
- System.out.println(entry.getKey() + "->");
- for (Map.Entry<String, Double> a : entry.getValue().entrySet()) {
- System.out.printf("Product: %s, Price: %.1f%n", a.getKey(), a.getValue());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment