Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Orders {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String command = sc.nextLine();
- LinkedHashMap <String, List<Double>> products = new LinkedHashMap<>();
- while(!"buy".equalsIgnoreCase(command)){
- String[] tokens = command.split("\\s+");
- String name = tokens[0];
- double price = Double.parseDouble(tokens[1]);
- double quantity = Double.parseDouble(tokens[2]);
- List <Double> list = new ArrayList<>();
- list.add(0, price);
- list.add(1, quantity);
- if(!products.containsKey(name)){
- products.put(name, list);
- } else {
- List <Double> list2 = new ArrayList<>();
- list2.add(0, price);
- list2.add(1, quantity + products.get(name).get(1));
- products.put(name, list2);
- }
- command = sc.nextLine();
- }
- products.entrySet().
- forEach(e-> System.out.printf("%s -> %.2f%n", e.getKey(), e.getValue().get(0) * e.getValue().get(1)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement