Untitled
unknown
java
2 years ago
613 B
6
Indexable
public static double order_cost(HashMap<Integer, Double> chemicals, ArrayList<Integer> glassware) { double totalCost = 0; Collections.sort(glassware); for (Integer quantity : chemicals.keySet()) { double price = chemicals.get(quantity); int kolb = Collections.binarySearch(glassware, quantity); if (kolb < 0) { kolb = -(kolb + 1); } if (kolb == glassware.size()) { kolb--; } totalCost += glassware.get(kolb) * price; } return totalCost; }
Editor is loading...