Find Jobs
Hire Freelancers

Cannibals & Missionaries

$10-30 USD

Fechado
Publicado há quase 10 anos

$10-30 USD

Pago na entrega
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 8:59PM, 5/21/2014** ## 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.) Input file and: There is an input file supplied. It will be named **[login to view URL]**. 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 **[login to view URL]** to store your output. ## Platform This assignment must done in Java
ID do Projeto: 5974593

Sobre o projeto

5 propostas
Projeto remoto
Ativo há 10 anos

Quer ganhar algum dinheiro?

Benefícios de ofertar no Freelancer

Defina seu orçamento e seu prazo
Seja pago pelo seu trabalho
Descreva sua proposta
É grátis para se inscrever e fazer ofertas em trabalhos
5 freelancers estão ofertando em média $61 USD for esse trabalho
Avatar do Usuário
Aucune proposition n'a encore été fournie.
$89 USD em 1 dia
5,0 (83 avaliações)
5,9
5,9
Avatar do Usuário
Hi, Please see the reviews that I have got while doing java projects. ping me to discuss things in detail. thanks
$55 USD em 7 dias
4,9 (14 avaliações)
3,8
3,8
Avatar do Usuário
A proposal has not yet been provided
$100 USD em 1 dia
0,0 (0 avaliações)
0,0
0,0
Avatar do Usuário
Its a simple task - I propose using 3 threads though - 1 for canibals, 1 for missionaries and 1 that sends the boat. Or it can be done with 2 - 1 for passengers ( canibals and missionaries ) and 1 that rows the boat. The main idea will be this - we put the passingers in a queue like structure and update the curent number of passengers. The row boat thread will chech - are there at least 3 ppl waiting if no it goes to sleep, if yes second check goes - are there at least 3 canibals - if yes - ship them, if no then checks is there at least 1 cannibal if yes then check if there are 2 missioneries - put them in a boat and add 1 cannibal - ship the boat, if there are no cannibals then check if there are 3 missionaries if yes - ship them if no - thread goes to sleep. the missionaries and canibals threads just add the passengers to the coresponsive queue and update the numbers.
$35 USD em 1 dia
0,0 (0 avaliações)
0,0
0,0
Avatar do Usuário
Hi I am a java developer I can handle your project. Please hire me so I can start workin with your project. Thanks a lot
$25 USD em 3 dias
0,0 (0 avaliações)
0,0
0,0

Sobre o cliente

Bandeira do(a) UNITED STATES
United States
0,0
0
Membro desde mai. 22, 2014

Verificação do Cliente

Obrigado! Te enviamos um link por e-mail para que você possa reivindicar seu crédito gratuito.
Algo deu errado ao enviar seu e-mail. Por favor, tente novamente.
Usuários Registrados Total de Trabalhos Publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Carregando pré-visualização
Permissão concedida para Geolocalização.
Sua sessão expirou e você foi desconectado. Por favor, faça login novamente.