Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // if a cyclist (and a pizza) is available then let them deliver the next pizza from the queue
  2. for(Map.Entry<Integer, Integer> i : cyclists.entrySet()){
  3. if (time > i.getValue() && !queue.isEmpty()) {
  4.  
  5. // obtain next pizza from the queue
  6. Pizza deliveredPizza = queue.poll();
  7.  
  8. // is it impossible to deliver this pizza on time?
  9. if (time + deliveredPizza.deliveryTime() > deliveredPizza.deadline()) {
  10.  
  11. // refund the pizza price with a penalty factor applied
  12. total -= deliveredPizza.latePrice();
  13.  
  14. // update the late pizza counts
  15. if (deliveredPizza.isUrgent())
  16. countLateUrgent++;
  17. else
  18. countLateStandard++;
  19.  
  20. } else // delivery on time was possible
  21. countOnTime++;
  22.  
  23. // calculate busy time for cyclist
  24. int fullTripTime = 2 * deliveredPizza.deliveryTime();
  25.  
  26. // update profit tally with delivery cost
  27. total -= Pizza.PerMinuteDeliveryCost * fullTripTime;
  28.  
  29. cyclists.put(i.getKey(), time+fullTripTime);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement