I need to write a daymanagerr that assigns time slots for orders in a restaurant.
That's the daymanager:
public DayManager (LocalDate date, int numberOfTimeSlots, int capacityPerSlot) { this.date = date; this.capacityPerSlot = capacityPerSlot; this.numberOfTimeSlots = numberOfTimeSlots; For each day I can choose the number of available slots and the capacity per slot (so if I choose 3 slots and a capacity of 3 per slot, that's 9 slots in total).
Every customer can state their preferred time slot (here: 0, 1 or 2) with their order.
Here's my class for adding orders:
public Optional<Integer> addOrder(Order order, int preferredSlot) { int givenSlot = 0, count = 1; List<Integer> slots = new ArrayList<Integer>(); List<Integer> slotsPerSlot = new ArrayList<Integer>(); if ((slots.size() * slotsPerSlot.size()) <= (numberOfTimeSlots * capacityPerSlot)) { if (slots.contains(preferredSlot) == false) { givenSlot = preferredSlot; slots.add(preferredSlot); slotsPerSlot.add(count); count++; } else if (slotsPerSlot.size() <= capacityPerSlot) { givenSlot = preferredSlot; slots.add(preferredSlot); slotsPerSlot.add(slotsPerSlot.size() + 1); } else { givenSlot = slots.get(slots.lastIndexOf(count)); } return Optional.of(givenSlot); } return Optional.empty(); } What I need help with:
With every new order I get, I need to check if there is still capacity left in that customers preferred slot. If there is capacity left, I assign that slot to him. If there is no capacity left in that slot, I assign the slot with the next lowest index (and available capacity). If there is no capacity left for that day, I simply return nothing.
I just can't figure out how to create a slotsPerSlot list for each slot and additionally I don't really know, how I could get the next lowest slot number.
https://stackoverflow.com/questions/66739162/creating-an-order-system-that-assigns-different-time-slots-based-on-their-capaci March 22, 2021 at 09:06AM
没有评论:
发表评论