Advertisement
deyanmalinov

06. Product Shop - print

May 29th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String line;
  7.         Map<String, LinkedHashMap<String, Double>> stores = new TreeMap<>();
  8.         while (!"Revision".equals(line= scan.nextLine())){
  9.             String[] gros = line.split(", ");
  10.             String store = gros[0];
  11.             String product = gros[1];
  12.             double price = Double.parseDouble(gros[2]);
  13.             stores.putIfAbsent(store, new LinkedHashMap<>());
  14.             stores.get(store).putIfAbsent(product, price);
  15.         }
  16. //        stores.forEach((shop, product) -> {
  17. //            System.out.println(shop + "->");
  18. //            product.forEach((prodName, price) ->{
  19. //                System.out.println(String.format("Product: %s, Price: %.1f", prodName, price));
  20. //            });
  21. //        });
  22.         for (String shopName : stores.keySet()) {
  23.             System.out.println(shopName + "->");
  24.             LinkedHashMap<String, Double> products = stores.get(shopName);
  25.             for (String proName : products.keySet()) {
  26.                 System.out.printf("Product: %s, Price: %.1f\n", proName, products.get(proName));
  27.             }
  28.            
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement