Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String line;
- Map<String, LinkedHashMap<String, Double>> stores = new TreeMap<>();
- while (!"Revision".equals(line= scan.nextLine())){
- String[] gros = line.split(", ");
- String store = gros[0];
- String product = gros[1];
- double price = Double.parseDouble(gros[2]);
- stores.putIfAbsent(store, new LinkedHashMap<>());
- stores.get(store).putIfAbsent(product, price);
- }
- // stores.forEach((shop, product) -> {
- // System.out.println(shop + "->");
- // product.forEach((prodName, price) ->{
- // System.out.println(String.format("Product: %s, Price: %.1f", prodName, price));
- // });
- // });
- for (String shopName : stores.keySet()) {
- System.out.println(shopName + "->");
- LinkedHashMap<String, Double> products = stores.get(shopName);
- for (String proName : products.keySet()) {
- System.out.printf("Product: %s, Price: %.1f\n", proName, products.get(proName));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement