Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question: Mouse! No~ (100 points) Assuming you have a cheese shop which has mouses problem. You, as the shop owner, would like to set
Question: Mouse! No~ (100 points) Assuming you have a cheese shop which has mouses problem. You, as the shop owner, would like to set up a list of traps to remove mouses. You don't know how many traps you need, so you decide to write a simulation for it. In this simulation, you have 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: Assuming 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. To get full marks, you need to: 1. Follow the printing format. (See the example output below) 2. Follow the simulation logic. 3. Correctly show the action and status. 4. The program should end when all mouses are removed. [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 ==== [Status] cheese left: 10 [Action] mouse-4 get caught by trap [Action] mouse-5 ate 3 grams of cheese [Status] cheese left: 7 [Action] mouse-2 get caught by trap [Action] mouse-1 get caught by trap [Action] mouse-3 ate 3 grams of cheese [Status] cheese left: 4 [Action] mouse-5 ate 2 grams of cheese [Status] cheese left: 2 [Action] mouse-3 ate 2 grams of cheese [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 ====== --------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started