RGAlex

O6. Product Shop

May 27th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ProductShop {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scan = new Scanner(System.in);
  8.         Map<String, Map<String, Double>> shopsInfo = new TreeMap<>();
  9.         String input;
  10.         while (!"Revision".equals(input = scan.nextLine())) {
  11.             String[] inputData = input.split(", ");
  12.             shopsInfo.putIfAbsent(inputData[0], new LinkedHashMap<>());
  13.             shopsInfo.get(inputData[0]).putIfAbsent(inputData[1], Double.parseDouble(inputData[2]));
  14.         }
  15.         shopsInfo.forEach((key, value) -> {
  16.             System.out.printf("%s->%n", key);
  17.             value.forEach((key1, value1) ->
  18.                     System.out.printf("Product: %s, Price: %.1f%n", key1, value1));
  19.         });
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment