Advertisement
Guest User

Orders

a guest
Dec 11th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 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.  
  7. Map<String, Double> products = new TreeMap<>();
  8. Map<String, Integer> secondProducts = new HashMap<>();
  9.  
  10. String line = scanner.nextLine();
  11.  
  12. while(!line.contains("buy")){
  13.  
  14. String[] tokens = line.split("\\s+");
  15. String name = tokens[0];
  16. Double price = Double.parseDouble(tokens[1]);
  17. int quantities = Integer.parseInt(tokens[2]);
  18.  
  19. if(!products.containsKey(name)){
  20. products.put(name, price);
  21. }else{
  22. products.put(name, products.get(name)+ price);
  23. }
  24.  
  25. if(!secondProducts.containsKey(name)){
  26. secondProducts.put(name, quantities);
  27. }else{
  28. secondProducts.put(name, secondProducts.get(name)+ quantities);
  29. }
  30.  
  31.  
  32. line = scanner.nextLine();
  33. }
  34.  
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement