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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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):
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY