Advertisement
dimitar96

Untitled

Jul 6th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Orders {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. LinkedHashMap<String, List<Double>> product = new LinkedHashMap();
  7. String comanda = scanner.nextLine();
  8. while (!comanda.equals("buy")){
  9. String [] tokens = comanda.split("\\s+");
  10. String name = tokens[0];
  11. double price = Double.parseDouble(tokens[1]);
  12. int quantities = Integer.parseInt(tokens[2]);
  13. // double total = price*quantities;
  14. if (product.containsKey(name)){
  15. List<Double> value =product.get(name);
  16. value.set(0,price);
  17. quantities+=value.get(1);
  18. value.set(1,quantities*1.00);
  19. product.put(name,value);
  20.  
  21. }else {
  22. List<Double> value = new ArrayList<>();
  23. value.add(price);
  24. value.add(quantities*1.00);
  25. product.put(name,value);
  26. }
  27. comanda=scanner.nextLine();
  28. }
  29. for (Map.Entry<String, List<Double>> entry : product.entrySet()) {
  30. List<Double> arr = entry.getValue();
  31. System.out.printf("%s -> %.2f%n",entry.getKey(),arr.get(0)*arr.get(1));
  32. }
  33.  
  34. // product.entrySet().forEach(e->e.);
  35.  
  36.  
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement