O-7 Create a cashier balance
Suppose you are a manager in a shop that sells clothes (like Karstadt or H&M etc).
The day begins, and the total balance is empty.
Your shop sells 3 kinds of goods.
t-shirts for 10$ each.
jeans for 30$ each.
jackets for 150$ each.
The shop has in stock 100 t-shirts, 100 jeans and 100 jackets. The total balance of the shop is 0.
These are properties that belong to your shop object and are shared across all employees.
The shop has 3 different cashiers so we can serve 3 clients maximum at the same time.
Create an object for every cashier and save inside:
the id of the cashier (from 1 to 3)
the fullname of the employee that works in the cashier now.
the number of customers this cashier has served. That is different for every cashier and begins with 0.
the balance of every cashier at any moment (begins empty).
These properties belong to every employee (every cashier) separately.
Create a function that deals with any new buy from a customer the following way:
Accepts what the customer has bought and how much of it does he want.
If the quantity of the specified good the customer wants to buy is ok and does not surpass
the limit of our stock for this material, then we calculate the fee the customer needs to pay and we update first the cashier's balance and the total balance of the shop as well. In the end we increase the cashier's number of customers that have been served by 1.
Else if some material is not enough because we havn't so many pieces left, then cancel the order by consoling log a descriptive message to the console. In this case of course we don't update any other value.
Ex.// cashier1.createSale(2, 2, 1) checks if the shop has 2 t-shirts left in stock, 2 jeans left and 1 jacket left. If some of these things is missing, we cancel the order. If not and all is fine, we update our stock (from 100 to 98 t-shirts etc), we add the cost of the order to cashier1 who made the sale, and of course we update the total balance of the shop with the cost of the order!
Additionally as bonus, create another function that is for refunding in case the customer is not happy with the material he bought and he wants to give it back and take his money back. In such a case it should be clear what he returns back, so we can update the stock and how much of this material is left, and of course update the cashier's balance and the shop's balance in general (the whole calculation result should be deducted from both balances). Don't forget to decrease the number of customers that have been served from this cashier.
Be careful! Some of the properties that are getting changed are shared through all cashiers (like the total shop balance, or how much of a specific material is left) while others are different for every cashier separately (for every employee).
You may want to think this first before you start implementing your architecture.