nus-cs2030 / 2122-s2

CS2030 repository and wiki for AY 2021/2022 Sem 2
MIT License
0 stars 0 forks source link

Level 8 Server interface ? #439

Open lihuicham opened 2 years ago

lihuicham commented 2 years ago

Hi, can someone kindly explain on how you approach level 8 ?

Should we implement a Server interface and have a HumanServer class and SelfCheckOut class, both implements the Server interface ?

Or, should the Server be a superclass instead of interface ?

Also, when the question said that all self check out counters share the same queue, does that mean that we will need a static customer queue in the self check out class, right ?

Can someone kindly explain on your thought process in approaching this level and what should I look out for when doing this level ? Thank you in advance !

nelsonchoo456 commented 2 years ago

Hi! You can create a SelfCheck class that extends your existing server class. Also, you can consider having an ImList in your Simulate8 class that acts as the shared queue, which was suggested in this issue!

Geraldworks commented 2 years ago

This was what I did

  1. SelfCheckout extends Server
  2. SelfCheckout holds the same queue as well
  3. Create a method in Shop to update all the SelfCheckouts to the same queue if the SelfCheckout takes a waiting customer
  4. Create a boolean method to check if the server is SelfCheckout or not
  5. Create a method in Shop to retrieve the SelfCheckout with the fastest ending timing so that your customers can go to it asap
feederalert commented 2 years ago

I used a similar approach as @Geraldworks except for point 5. Once a self checkout is done, it will just serve the next customer in the shared customer queue. Remember to update all self checkout queues when you serve a customer as well.

YangHaoying commented 2 years ago

Hii! My approach was different from the above comments as I did not have a new SelfCheck class. I added a boolean constructor inside my Server class to distinguish SelfChecks from normal servers and whenever a SelfCheck's queue is updated, I update the shop so that all other SelfChecks' queues are updated accordingly as well. I also changed the Server class's toString() to fulfil the required formant of printing SelfCheck servers. So technically all of my servers are still of the same Server class and imo this might be more convenient. Hope it helps!

celine-chung commented 2 years ago

hello! whether or not you choose to implement it as an interface or superclass is up to you and whatever way you choose will probably be able to work:-) BUT to address your 4th question, no you can't use a static variable for the shared queue because for this mod all variables are declared private final and since static attributes are the same across the entire class, there's no way to change it later.

all the methods mentioned by everyone above work! but i took a bit of a different approach which i felt modelled the question more closely: since the question said that "customers are always waiting at counter k + 1 even though they may be served by other counters later" what i did was to have the first counter have the same qMax as the human servers but all the subsequent counters have a qMax of 0! and then once i get to the wait event, if it is in the shared queue, i'll redirect the customer to the next free counter instead when scheduling the serve event! all the best!!