Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Orders {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- LinkedHashMap<String, List<Double>> product = new LinkedHashMap();
- String comanda = scanner.nextLine();
- while (!comanda.equals("buy")){
- String [] tokens = comanda.split("\\s+");
- String name = tokens[0];
- double price = Double.parseDouble(tokens[1]);
- int quantities = Integer.parseInt(tokens[2]);
- // double total = price*quantities;
- if (product.containsKey(name)){
- List<Double> value =product.get(name);
- value.set(0,price);
- quantities+=value.get(1);
- value.set(1,quantities*1.00);
- product.put(name,value);
- }else {
- List<Double> value = new ArrayList<>();
- value.add(price);
- value.add(quantities*1.00);
- product.put(name,value);
- }
- comanda=scanner.nextLine();
- }
- for (Map.Entry<String, List<Double>> entry : product.entrySet()) {
- List<Double> arr = entry.getValue();
- System.out.printf("%s -> %.2f%n",entry.getKey(),arr.get(0)*arr.get(1));
- }
- // product.entrySet().forEach(e->e.);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement