Em Andamento

Cannibals & Missionaries

Cannibals & Missionaries

**Problem Description**

A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river, but it only seats three people, and must always carry a full load. In order to guarantee the safety of the missionaries, you cannot put one missionary and two cannibals in the same boat (because the cannibals would gang up and eat the missionary), but all other combinations are legal. You are to write two procedures: **MissionaryArrives** and **CannibalArrives**, called by a missionary or cannibal when it arrives at the river bank. The procedures arrange the arriving missionaries and cannibals into safe boatloads; once the boat is full, one thread calls *RowBoat* and after the call to *RowBoat*, the three procedures then return. There should also be no undue waiting: missionaries and cannibals should not wait if there are enough of them for a safe boatload.

**Please also write a one page design documentation**

**The assignment has to be done in Java and Due by 11:59AM, Aug-11-03**

## Deliverables

Cannibals & Missionaries

**Problem Description**

A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river, but it only seats three people, and must always carry a full load. In order to guarantee the safety of the missionaries, you cannot put one missionary and two cannibals in the same boat (because the cannibals would gang up and eat the missionary), but all other combinations are legal. You are to write two procedures: **MissionaryArrives** and **CannibalArrives**, called by a missionary or cannibal when it arrives at the river bank. The procedures arrange the arriving missionaries and cannibals into safe boatloads; once the boat is full, one thread calls *RowBoat* and after the call to *RowBoat*, the three procedures then return. There should also be no undue waiting: missionaries and cannibals should not wait if there are enough of them for a safe boatload.

**Please also write a one page design documentation**

**The assignment has to be done in Java and Due by 11:59AM, Aug-11-03**

Common Questions

1. How do we use threads to solve this problem?

It's up to you. Remember, a big part of this class is learning how to design code. A lot of these problems have more than one correct solution. Whatever you do, MAKE SURE to tell the grader what you did in your writeup! If the grader doesn't understand what you did, he won't give you any points. L

That said, here are some suggestions. One is you can have one thread exist for each Missionary or Cannibal that is there -- in other words, if you have 10 missionaries and 5 cannibals waiting for a boat, there would be 15 threads. Another way you can do it is have a Missionary thread and Cannibal thread; and each one keeps track of how many of its kind of people are waiting -- in this case, there would be 2 threads no matter how many missionaries and cannibals there are.

These are just two suggestions. You can do something else if you have a better idea, as long as it involves multiple threads that are communicating via locks and condition variables. (Well, I should say you can do ALMOST anything else... silly solutions will not get points.)

2. What happens when the missionaries and cannibals get across the river?

They disappear. The point of this assignment is just to get the missionaries and cannibals arranged into safe boatloads. Once the groupings are determined, you can simply print out a message saying what happened (e.g,. "Boat leaving with Missionary 4, Missionary 9, and Cannibal 1!").

Testing:

To ensure that your project functions properly, you should create a test file that will exhibit all possible combinations of missionary/cannibal boat loads. Test incrementally. Code one case, test it, then add another case. After the addition ensure that the previous case was not ruined, and ensure that the new case works. I cannot emphasize enough how much time this will save you. J

Input file and:

There is an input file supplied. It will be named **[url removed, login to view]**. Each line in the file will contain a single request. A request for a Missionary will look like: “Missionary 1??, and a cannibal will look like: “Cannibal 1.?? Essentially it will be the type of passenger, followed by an id number.

Output file:

The format for the output file should be something like following.

"Boat leaving with Missionary 4, Missionary 9, and Cannibal 1!"

There should be as many lines printed as the (total number of requests)/3. You should also generate an output file **[url removed, login to view]** to store your output.

## Platform

This assignment must done in Java

Habilidades: Engenharia, Java, MySQL, PHP, Arquitetura de software, Teste de Software

Ver mais: missionaries cannibals problem java code output, missionaries cannibals java, missionaryarrives rowboat, missionaries cannibals problem solution java code, what is new in java 1.5, what is an assignment problem, two lines crossing, total safety, solve the assignment problem, solve assignment problem, solution to assignment problem, solution of assignment problem, problem solution assignment, problem of points solution, lines that cross at one point, learning to write code, learning point, java 1.5 documentation, java 1.4 documentation, it river, how to solve assignment problem, eat more, cross with two lines, common questions, c code for assignment problem

Acerca do Empregador:
( 3 comentários ) United States

ID do Projeto: #2961364

Premiar a:

vasilpanayotov

See private message.

$17 USD em 2 dias
(8 Avaliações)
3.2

10 freelancers estão ofertando em média $43 para este trabalho

alcanta

See private message.

$38.25 USD in 2 dias
(28 Comentários)
4.9
seirus

See private message.

$5.95 USD in 2 dias
(35 Comentários)
4.0
uorgs

See private message.

$4.25 USD in 2 dias
(4 Comentários)
3.5
xeontechlogixvw

See private message.

$25.5 USD in 2 dias
(13 Comentários)
3.6
vasilevalaiba

See private message.

$25.5 USD in 2 dias
(9 Comentários)
2.5
eugeneturin

See private message.

$170 USD in 2 dias
(6 Comentários)
2.7
bogdancardos

See private message.

$12.75 USD in 2 dias
(2 Comentários)
0.0
tsltd

See private message.

$63.75 USD in 2 dias
(0 Comentários)
0.0
simonascott

See private message.

$68 USD in 2 dias
(0 Comentários)
0.0