Tuesday, September 10, 2019

Programming Project in Java Assignment Example | Topics and Well Written Essays - 2000 words

Programming Project in Java - Assignment Example Per problem counter semaphore should be initialized to '3'. b. Secondly, a binary semaphore to keep track whether a customer is being served by a Server or not. This will avoid customer thread to gain access of multiple counters at a time. 3. Cash Register - Like Counter location, cash register is also shared by customers. Since, there exist a single cash register and only one customer can access it at given moment. A binary semaphore can be used to control customers waiting to pay from paying together, but would ensure they pay one by one. So, four different semaphores are needed to handle concurrency of Customer and Server as per given problem. Use cases:- Customer Server Class Diagram:- Both, Customer and Server extend Thread class. However, both classes have different sets of responsibilities. Customer 1. Step in to Burrito Brothers shop, if there is space available. 2. After stepping in, wait till customer becomes a customer with smallest order in waiting Area. 3. Once, customer becomes the customer with smallest order aquaire a free counter. 4. Leave counter and join waiting Area. 5. If more burritos are needed keep performing steps 3 & 4. 6. If order is complete wait for cash register to get free. 7. Once cash register is free leave waiting Area and acquire cash register. 8. Pay. 9. Leave cash register. 10. Leave Burrito Brothers. Server 1. Wait for customer to serve. 2. Once customer is at counter, prepare three or less burritos. 3. Handover them and again go to step 1. Additional, two classes are needed in the solution which are not mentioned in class diagram. 1. CustomerGenerator - A class to generate new customers with random orders. 2. World - A class which creates...Since, there exist a single cash register and only one customer can access it at given moment. A binary semaphore can be used to control customers waiting to pay from paying together, but would ensure they pay one by one. Since, customer with smallest order needs to get change to aquireCounter first Waiting Area is implemented as TreeSet which automatically sorts objects, if object implements Comparable interface. Customers just need to check whether they are first in Tree Set to know whether they are eligible to acuire Counter Location, if available. World.log("Admitted one customer " +customer.getCustomerName() + ", additional space for " + customerSemaphore.availablePermits() + " customers available. Waiting area consits of " + customersWaitingForBurrito.toString()); World.log(serverName + " made " + burritosToMake + " burritos for " + customerToServe.getCustomerName() + ", customer still requires " + (customerToServe.getOrderBurritoCount() - customerToServe.getAcceptedBurritos()) + " burritos.");

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.