For my assignment I need to write a daymanager 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 (I can only use this class to solve my problem):
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 figured that using two ArrayLists would problably be the best solution, but just can't figure out how to create a slotsPerSlot-list for each slot. And additionally after tackling that problem, I don't really know, how I could get the next lowest slot number from those ArrayLists to assign that slot-number instead.
https://stackoverflow.com/questions/66740220/creating-an-order-timeslot-system-for-a-restaurant-with-changable-slot-sizes March 22, 2021 at 12:07PM
没有评论:
发表评论