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