Write a java recursive program to solve the "Missionaries and Cannibals" problem:Three missionaries and three cannibals come to a river and find a boat that holds two. If the cannibals ever outnumber...


Write a java recursive program to solve the "Missionaries and Cannibals" problem:Three missionaries and three cannibals come to a river and find a boat that holds two. If the cannibals ever outnumber the missionaries on either bank, the missionaries will be eaten. How might they cross safely? Input a character from the keyboard either a c (cannibal) or m (missionary). Check case and error check inputs. The output should include the initial problem, the moves you make, and a "picture" of the current state of the puzzle after each move (round). The final output should include the total number of rounds needed to solve the problem. Finally, ask the user if they wish to run the program again. The program must use recursion as part of the solution. Refer to the sample output below.


Sample Run (partial):Crossing the River-----------------------------------------Round 0Left RightMMMCCCBoatFirst passenger (c for cannibal, m for missionary): HIllegal Input!First passenger (c for cannibal, m for missionary): mSecond passenger (c for cannibal, m for missionary, n for none): c-----------------------------------------Round 1Left RightMMCC MC BoatFirst passenger (c for cannibal, m for missionary): CSecond passenger (c for cannibal, m for missionary, n for none): cIllegal input!Second passenger (c for cannibal, m for missionary, n for none): n-----------------------------------------Round 2Left RightMMCCC M BoatMissionaries eaten by cannibals! You lose!


























COSC 2436 F217 Run again? (Y/N): YCrossing the River-----------------------------------------Round 0 Left RightMMMCCCBoatFirst passenger (c for cannibal, m for missionary): mSecond passenger (c for cannibal, m for missionary, n for none): c-----------------------------------------Round 1Left RightMMCC MC BoatFirst passenger (c for cannibal, m for missionary): MSecond passenger (c for cannibal, m for missionary, n for none): n-----------------------------------------Round 2Left RightMMMCC C BoatFirst passenger (c for cannibal, m for missionary): cSecond passenger (c for cannibal, m for missionary, n for none): c-----------------------------------------....................................-----------------------------------------Round 15Left RightCC MMMCBoatFirst passenger (c for cannibal, m for missionary): cSecond passenger (c for cannibal, m for missionary, n for none): -----------------------------------------Congratulations! You win the game in 15 rounds!Run again? (Y/N):

Jun 01, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here