Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Map<Double, Integer>> map = new LinkedHashMap<>();
- String command = scanner.nextLine();
- while (!"buy".equals(command)) {
- String[] array = command.trim().split("\\s+");
- String product = array[0];
- double price = Double.parseDouble(array[1]);
- int quantity = Integer.parseInt(array[2]);
- if (map.containsKey(product)) {
- map.get(product).put(price, map.get(product).get(price) + quantity);
- } else {
- map.putIfAbsent(product, new LinkedHashMap<>());
- map.get(product).put(price, quantity);
- }
- command = scanner.nextLine();
- }
- map
- .forEach((k, v) -> {
- System.out.printf("%s -> ", k);
- v
- .forEach((key, value) -> System.out.printf("%.2f%n", key * value));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement