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 Example: Boxes in sequential order: R represents a rabbit and C represents a carrot in the boxes. R R R C R C Each rabbit will have a name. The aim of all rabbits is to go to the last box numbered as 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 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: Enter number of boxes: Enter carrot producing rate X: Enter carrot timeout Y: Enter sleeping time for rabbits Z: The game starts Remzi jumps to box Canan jumps to box Person puts carrot to box Remzi jumps to box Necati jumps to box Remzi jumps to box Person puts carrot to box Remzi eats carrot in box Carrot in box removed Necati jumps to box Canan jumps to box Necati has points Canan has points Remzi jumps to box Remzi has points Game over!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
