Untitled
Anonymous
java
01/17/2023 1:06 PM
820 B
12
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...