Question: Write a multithreaded Java program for the following game. In the game, we have some boxes ordered sequentially. We have some rabbits and these rabbits

Write a multithreaded Java program for the following game. In the game, we have some boxes ordered sequentially. We have some rabbits and these rabbits jump from one box to another. There is a person which puts carrots into boxes for rabbits. Number of rabbits and boxes are determined at the beginning of the program as a parameter. All rabbits will start the game from the first box numbered as [0]. Example: Boxes in sequential order: R represents a rabbit and C represents a carrot in the boxes. 0123456 R17 R3, R5 C1 R4...99 C2 Each rabbit will have a name. ... The aim of all rabbits is to go to the last box numbered as [99] by jumping from one box to another. Rabbits can only jump from one box to the next box right after it. They cannot jump back. If a rabbit finds a carrot in the box, it eats it and get 1 point. The person puts a carrot to a box randomly for every X milliseconds. If rabbits do not eat the carrot within Y milliseconds, the carrot is removed from the box. X and Y values should be entered at the beginning. More than one rabbit can be in the same box at the same time. Each rabbit will have Z milliseconds delay between jumps. Value of Z should be entered at the beginning. After each jump and after eating a carrot, the rabbits announce (print) their states. After putting a carrot, the person announces (print) the box number of the carrot. After a carrot is removed, it is announced (printed). At the end of the game rabbits announce their total score. The program starts: Enter number of rabbits: 5 Enter number of boxes: 100 Enter carrot producing rate (X): 300 Enter carrot timeout (Y): 600 Enter sleeping time for rabbits (Z): 100 The game starts Remzi jumps to box 1 Canan jumps to box 1 Person puts carrot to box 3 Remzi jumps to box 2 Necati jumps to box 1 Remzi jumps to box 3 Person puts carrot to box 66 Remzi eats carrot in box 3.. Carrot in box 66 removed .. Necati jumps to box 99 Canan jumps to box 99 Necati has 4 points Canan has 3 points Remzi jumps to box 99 Remzi has 6 points Game over!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!