IMPLEMENTING JAVA THREAD Assuming that I have a cheese shop that has mouses problem. I would like
Question:
IMPLEMENTING JAVA THREAD
Assuming that I have a cheese shop that has mouses problem.
I would like to set up a list of traps to remove mouses. I don't know how many traps I will need, so I need to design a simulation for it using Java Programming.
In this simulation, A cheese machine which can generate 10 grams of cheese to a cheese container every 2 seconds. In addition, there are X number of mouses and Y traps.
Every second, a mouse will consume 1-3 grams from the cheese container. If cheese container does not contain any cheese, the mouse will wait for it. Before a mouse eating cheese, it will have 50% chance to get caught by a trap. Each trap can only catch one rat.
The trap can only be available again when the shop owner removes the caught mouse. Every 5 seconds, the shop owner will check the traps and remove all the caught mouses. Finally, after all the mouses are removed from the shop, your simulation needs to print out the total loss of cheese in grams. More details: Assume that a mouse would like to consume 3 grams of cheese, however, the container only has 1 gram left, then the mouse can only consume 1 gram of it. Each mouse has an integer number representing the id of the mouse. e.g., mouse-1 or mouse-3. Please print the divider "============" when the owner removed mouses for better readability. The cheese container starts with a default number of cheese.
Here the output:
[Status] cheese left: 0 [Action] Cheese Machine add 10 grams of cheese [Status] cheese left: 10 [Action] mouse-5 ate 3 grams of cheese [Status] cheese left: 7 [Action] mouse-3 ate 1 grams of cheese [Status] cheese left: 6 [Action] Cheese Machine add 10 grams of cheese [Status] cheese left: 16 [Action] mouse-5 ate 1 grams of cheese [Status] cheese left: 15 [Action] mouse-3 ate 1 grams of cheese [Status] cheese left: 14 ======================================================== [Action] Store owner remove mouse-4 [Action] Store owner remove mouse-2 [Action] Store owner remove mouse-1 ======================================================== [Action] mouse-5 ate 1 grams of cheese [Status] cheese left: 13 [Action] mouse-3 ate 3 grams of cheese [Status] cheese left: 10 [Action] Cheese Machine add 10 grams of cheese [Status] cheese left: 20 [Action] mouse-5 get caught by trap [Action] mouse-3 get caught by trap [Action] Cheese Machine add 10 grams of cheese [Status] cheese left: 30 ======================================================== [Action] Store owner remove mouse-5 [Action] Store owner remove mouse-3 ======================================================== [Status] Total cheese lost = 20