Write a CONCURRENT program simulating the 7 dwarfs going to a diamond mine to co
ID: 3576180 • Letter: W
Question
Write a CONCURRENT program simulating the 7 dwarfs going to a diamond mine to collect treasures and bring them home. The program will use Java concurrency and threads to simulate the 7 dwarfs working together in PARALLEL to get all the diamond pieces from the mine. (Each dwarf should be a separate thread of execution working to collect diamonds from a shared resource (Diamonds) Specifics: There are 1,000 diamonds in the mine Your dwarfs live in a hamlet roughly 10 miles from the mine. However, the dwarfs take the trip at different speeds each time they head out. Simulate this by putting the thread to sleep from 5-10 seconds at the beginning of the diamond collection method. Each dwarf can carry from 10-50 diamond pieces per load (randomize this) When the dwarfs get home, they should off load the diamonds, and then sleep for 10 20 seconds before heading back out to the mine. (Dwarfs don't need much rest!!) Your program should report the following o Each time a dwarf leaves the hamlet (and dwarf name) o When a dwarf arrives at the mine (and name) When a dwarfarrives back home and how many diamonds he's carrying When a dwarf arrives home also print out how many diamonds are left in the mine Continue the simulation until all the pieces have been delivered home, then report: o "all Diamonds have been collected" o Also, report how many diamonds each dwarf (thread) collected.Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int n)
produce a mathematician array "prime[0..n]" and initialize
// all entries it as true. a worth in prime[i] can
// finally be false if i isn't a chief, else true.
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
// If prime[p] isn't modified, then it's a chief
if (prime[p] == true)
}
// Print all prime numbers
for (int p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}
// Driver Program to check on top of operate
int main()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.