<!-- saved from url=(0106)file:///D:/source/repos/konkurens/BSc/assignments/2022-23-1-assignment2-PigMent/2022-23-1-assignment2.html -->
<html class="translated-ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link type="text/css" rel="stylesheet" charset="UTF-8" href="./2022-23-1-assignment2_en_files/translateelement.css"></head><body><hr class="solid" style="border-top: 5px solid grey;">
<h1 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Things to know</font></font></h1>
<hr class="solid" style="border-top: 5px solid grey;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Auxiliary files</font></font></h4>
<p style="text-align: justify; color:red"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">skeleton + example output placeholder</font></font></p>
<hr class="solid" style="border-top: 1px solid grey;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Tasks and assessment</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The assignment consists of three interrelated tasks. </font><font style="vertical-align: inherit;">You start the solution by preparing the basic task, and when you are ready with this, you can supplement your program with the contents of the second, supplementary task. </font><font style="vertical-align: inherit;">You do not need to solve the third, diligence task for the maximum 15 points.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">You must solve the basic task. </font><font style="vertical-align: inherit;">The basic task has sub-tasks, by skipping (or dumbing down) your program will still work. </font><font style="vertical-align: inherit;">You can get partial points for a partially solved basic task. </font><font style="vertical-align: inherit;">The prerequisite for a successful submission is that your subprogram works, i.e. it can be compiled and run.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">By solving another task incorrectly, you can spoil your existing, partially finished, but functional program. </font><font style="vertical-align: inherit;">If you already have a working program, you should create the additional tasks in a new file.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The text of the task is so long because it is readable. </font><font style="vertical-align: inherit;">The program itself, which you have to prepare, is particularly short. </font><font style="vertical-align: inherit;">The entire set of tasks can be solved with a program of around 100 lines, consisting of a single file, without comments and empty lines.</font></font></p>
<hr class="solid" style="border-top: 1px solid grey;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Administration</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">When entering, you can enter a maximum of 1 file each for the basic task and the additional task. </font><font style="vertical-align: inherit;">Of course, the additional task also includes the basic task, but you will receive separate points for the two tasks during evaluation. </font><font style="vertical-align: inherit;">So, for example, if you have 5 backups for the basic task and 3 for the additional task, you choose the best solution for the basic task and the best solution for the additional task.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Submit your solutions in zip. </font><font style="vertical-align: inherit;">The file name should be your Neptune code. </font><font style="vertical-align: inherit;">In the folder Task1 and Task2, your solution to the basic task and additional task should be placed. </font><font style="vertical-align: inherit;">A solution </font></font><code>PigMent.java</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">must consist of a single file. </font><font style="vertical-align: inherit;">In the case of diligence, you have to do the same, you should also have a Task3 folder!</font></font></p>
<hr class="solid" style="border-top: 1px solid grey;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Auxiliary equipment</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">To make the task easier to follow, the names of the classes, methods and variables are given in each task description. </font><font style="vertical-align: inherit;">Start from the initial file containing only these names </font></font><code>PigMent.java</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">, so you don't waste time digging out and copying the variable names from the task one by one. </font><font style="vertical-align: inherit;">At the beginning of the initial </font></font><code>String</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">file, you can also see the individual values that must be written to the screen at certain points in the program. </font><font style="vertical-align: inherit;">This also serves the purpose of not having to stop your work while coding and start searching in the text of the task.</font></font></p>
<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Names with all capital letters denote constants. </font><font style="vertical-align: inherit;">These can be found with already set values in the source file.</font></font></p>
<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">In the task description, "mass", "size" and "weight" are synonyms. </font><font style="vertical-align: inherit;">In this fictional world, the gravitational field is uniform. </font><font style="vertical-align: inherit;">We do not deal with density differences.</font></font></p>
<br>
<hr class="solid" style="border-top: 5px solid green;">
<h1 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Basic task (9p)</font></font></h1>
<h3 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Executor, Runnable, synchronized, AtomicInteger, wait-notify</font></font></h3>
<h4 style="text-align: center; color: gray"><i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Difficulty: I can do this!</font></font></i></h4>
<hr class="solid" style="border-top: 5px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Story Time</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">On a planet called </font></font><i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">PigMent</font></font></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;"> , the living world hid underground from the hot sun. </font><font style="vertical-align: inherit;">An exception to this is a strange species of pig that has adapted to the cruel environment. </font><font style="vertical-align: inherit;">As a result of a strange mutation, a purple pigment appeared in their skin, with the help of which they reflect most of the harmful ultraviolet radiation, and from the absorbed light, they develop energy through photosynthesis. </font><font style="vertical-align: inherit;">Pigs are gender-neutral, so once they reach a certain size, they reproduce by dividing like bacteria. </font><font style="vertical-align: inherit;">Each pig has an independent will and decision-making ability, so you have to treat each pig separately and in parallel with the other pigs during the program.</font></font></p>
<hr class="solid" style="border-top: 1px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">pigSleep - 1 point</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Not everything happens immediately. </font><font style="vertical-align: inherit;">Big things have to wait.. or sleep..</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">It is no different here, even in the society of pigs there is sometimes idle time. </font><font style="vertical-align: inherit;">To do this, write the </font></font><code>pigSleep()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">method that </font><font style="vertical-align: inherit;">blocks the calling thread for a time between </font></font><code>TICK_MIN</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">and milliseconds.</font></font><code>TICK_MAX</code><font style="vertical-align: inherit;"></font></p>
<hr class="solid" style="border-top: 1px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">PhotoPig - 1 point</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The pig breed is </font></font><code>PhotoPig</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">described by a named class. </font><font style="vertical-align: inherit;">In order to be able to track individual pigs, each copy has a unique identifier ( </font></font><code>id</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">). </font><font style="vertical-align: inherit;">Furthermore, their weight can be set parametrically at birth ( </font></font><code>mass</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">), which is also stored by the class.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Make sure that the mass in the constructor is the value received as a parameter, and </font></font><code>AtomicInteger</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">resolve with the help of a globally available (you can also call </font></font><code>id</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">it ) that each pig instance receives the number as an identifier as the number of times it was born.</font></font></p>
<hr class="solid" style="border-top: 1px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">pigSay - 1 point</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Although the piglets tolerate the weather well, their brains are slightly cooked in the high heat. </font><font style="vertical-align: inherit;">Because of this, they tend to shout nonsense on a regular basis.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">By </font></font><code>pigSay(String msg)</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">writing the method, give voice to the refs. </font><font style="vertical-align: inherit;">The method should be written to the console, as well as the </font></font><code>msg</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">name of the speaker. </font><font style="vertical-align: inherit;">To do this, write the ID and the mass in front of the message.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Only one pig can speak at a time! </font><font style="vertical-align: inherit;">Otherwise it would just be noise.</font></font></p>
<hr class="solid" style="border-top: 1px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">eatLight() and run() - 4 points</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Pigs lose weight continuously during their metabolism. </font><font style="vertical-align: inherit;">Catabolic (degrading) metabolic processes are compensated by anabolic (constructive) metabolic processes. </font><font style="vertical-align: inherit;">However, this requires building materials. </font><font style="vertical-align: inherit;">This is why people eat it. </font><font style="vertical-align: inherit;">Here, however, there are photosynthesizing pigs, so it happens a little differently with them. </font><font style="vertical-align: inherit;">They lay down to sleep instead of eating. </font><font style="vertical-align: inherit;">When they've sucked themselves up, they head home with light. </font><font style="vertical-align: inherit;">On the way home, the building processes take place in their bodies, which is why they are more muscular and fatter, so they will be bigger than before. </font><font style="vertical-align: inherit;">When they reach a certain critical mass, they split into two. </font><font style="vertical-align: inherit;">The original pig also remains, but half of its mass becomes self-aware and separates from the mother's body.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The </font></font><code>PhotoPig</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">class </font></font><code>Runnable</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">should be an implementation, so </font><font style="vertical-align: inherit;">individual pigs can be thrown into an </font></font><code>ExecutorService</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">object ( ). </font></font><code>pigPool</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Make sure that each pig can live in parallel with the other pigs!</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The beginning of a pig's life should begin with a </font></font><code>"Beware world, for I'm here now!"</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">cry and end with a </font></font><code>"I have endured unspeakable horrors. Farewell, world!"</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">sigh. </font><font style="vertical-align: inherit;">Between the two, they lie down to bask again and again. </font><font style="vertical-align: inherit;">Put the sunning and its consequence (division) in the </font></font><code>eatLight()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">method. </font><font style="vertical-align: inherit;">Its return value should indicate whether it met its fate while sunbathing. </font><font style="vertical-align: inherit;">The method should return </font></font><code>true</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">a value if the pig is still alive. </font><font style="vertical-align: inherit;">The method should be called again and again </font></font><code>eatLight()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">until </font></font><code>false</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">a value is returned. </font><font style="vertical-align: inherit;">In the basic task, the animals cannot yet die, so an endless cycle develops here. </font><font style="vertical-align: inherit;">This is completely normal, this is not a mistake!</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The </font></font><code>eatLight()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">method treats both anabolic (mass-increasing) and catabolic (mass-reducing) processes. </font><font style="vertical-align: inherit;">After the pig has </font></font><code>pigSleep()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">been out in the sun for a while, we can start counting the changes. </font><font style="vertical-align: inherit;">The mass obtained from sunbathing is determined by the capacity of the internal organs, so it is independent of the weight of the pig. </font><font style="vertical-align: inherit;">Get </font></font><code>FEED</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">extra mass at a fixed price. </font><font style="vertical-align: inherit;">The weight lost already depends on the weight of the pig, lose weight in </font></font><code>mass / BMR</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">value. </font><font style="vertical-align: inherit;">Note that the higher the weight of the pig, the worse the ratio of weight gained and lost. </font><font style="vertical-align: inherit;">If this ratio is less than 50%, then the pig should be split in two! </font><font style="vertical-align: inherit;">To help, here is the formula: </font></font><code>mass / BMR > FEED / 2</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">, if this is true, then that is also true</font></font><code>eatLight()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">division should take place at the end of the method. </font><font style="vertical-align: inherit;">The original pig remains at half the mass. </font><font style="vertical-align: inherit;">With the other half of the crowd, create a new pig that </font></font><code>ExecutorService pigPool</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">will bring itself to life. </font><font style="vertical-align: inherit;">If we have reached the </font></font><code>MAX_POP</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">number of births indicated by the value, then the newborn should not come to life by accident!</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">After eating light, the pigs squeal in joy </font></font><code>"Holy crap, I just ate light!"</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">, and when dividing, they </font></font><code>"This vessel can no longer hold the both of us!"</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">squeal stupidity.</font></font></p>
<hr class="solid" style="border-top: 1px solid green;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">main() - 2 points</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">At the beginning of the simulation, set a </font></font><code>INIT_POP</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">number of pigs on the road. </font><font style="vertical-align: inherit;">The mass of each should initially </font></font><code>INIT_MASS</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">be</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">If the global pig counter has reached the </font></font><code>MAX_POP</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">value, the newly born pig should send a signal, causing the simulation to end. </font><font style="vertical-align: inherit;">In theory, the simulation can run indefinitely, but in practice we want to interrupt it after a certain number of pig births. </font><font style="vertical-align: inherit;">Since we are interrupting the simulation, rather than waiting for it to finish, there is no need to fiddle with a "nice" shutdown. </font><font style="vertical-align: inherit;">It's perfectly fine if you use it </font></font><code>pigPool.shutdownNow()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">to immediately terminate all running threads.</font></font></p>
<hr class="solid" style="border-top: 5px solid orange;">
<h1 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Additional task (6p)</font></font></h1>
<h3 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">BlockingQueue, ReentrantLock, Condition</font></font></h3>
<h4 style="text-align: center;; color: gray"><i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Difficulty: I mean.. I like a challenge, right? </font><font style="vertical-align: inherit;">Right?!</font></font></i></h4>
<hr class="solid" style="border-top: 5px solid orange;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Story Time</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The pigs have become so mad from the gamma radiation caused by the many solar flares that they no longer despise cannibalism. </font><font style="vertical-align: inherit;">According to them, this is just a more efficient and faster form of nutrition. </font><font style="vertical-align: inherit;">Pigs now come out of their hiding places not only to sunbathe, but also to hunt.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">First, they walk around busy places looking for prey. </font><font style="vertical-align: inherit;">If they find a pig no bigger than them, they look at it as food. </font><font style="vertical-align: inherit;">While watching, it may happen that another pig looks at him as a snack. </font><font style="vertical-align: inherit;">Once the target is found, the pig hides, then the other hungry pigs can't see him. </font><font style="vertical-align: inherit;">If they haven't eaten him before, they won't during this hunt either.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">If he did not find prey, or while he was hiding, someone else dropped his prey, or the prey hung, then the hunt is unsuccessful. </font><font style="vertical-align: inherit;">In other cases, the hunt is successful and the pig will be enriched with half the weight of the prey. </font><font style="vertical-align: inherit;">The life of a killed pig ends.</font></font></p>
<p style="text-align: justify;"></p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Regardless of success, the hunt is exhausting, so the pigs lie down to rest for the day before heading home. </font><font style="vertical-align: inherit;">They will then become visible to other hunters again. </font><font style="vertical-align: inherit;">In return, they get the extra mass even after photosynthesis. </font><font style="vertical-align: inherit;">If they haven't eaten it by the time he wakes up, they won't eat it while sunbathing. </font><font style="vertical-align: inherit;">On the way home, the weight loss and division resulting from metabolism take place in a similar way as in the basic task.</font></font><p></p>
<hr class="solid" style="border-top: 1px solid orange;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">openArea and aTerribleThingToDO() - 4 points</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Use a </font></font><code>PriorityBlockingQueue</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">( </font></font><code>openArea</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">) to enable the pigs to register when they are visible and when they are not visible to the hunters. </font><font style="vertical-align: inherit;">Such an object works similarly to any </font></font><code>BlockingQueue</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">. </font><font style="vertical-align: inherit;">Its only interesting feature is that, in addition to the size, when instantiating, you can also specify an arrangement. </font><font style="vertical-align: inherit;">If an element is removed, it will not return the oldest inserted object, but the smallest one. </font><font style="vertical-align: inherit;">Help with instantiation: </font></font><code>new PriorityBlockingQueue<>(MAX_POP, (a,b) -> a.mass - b.mass);</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">. </font><font style="vertical-align: inherit;">The second argument is a lambda expression, which says that two </font></font><code>PhotoPig</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">objects can be sorted by the difference in their masses.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">During hunting, after they have spotted a prey, </font></font><code>pigSleep()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">it takes time for them to hide well in order to catch it. </font><font style="vertical-align: inherit;">The pigs should be </font></font><code>pigSleep()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">available during hunting and sunbathing, i.e. they should add themselves to the </font></font><code>openArea</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">line before that, and then </font></font><code>openArea.remove(this)</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">take them out with the instruction. </font></font><code>peek()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">In the case of hunting, look for prey </font><font style="vertical-align: inherit;">before waiting . </font><font style="vertical-align: inherit;">This means that while they hide (which is </font></font><code>pigSleep()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">time), the prey has some chance to hang around.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">If they can't take themselves out, someone has already taken them out, i.e. eaten them. </font><font style="vertical-align: inherit;">Otherwise, everything is fine and they can try to take out their own prey. </font><font style="vertical-align: inherit;">If they don't know, it's either because they were the smallest and they chose themselves as prey, or in the meantime, the pig they wanted to kill had already escaped (went home) or someone else had eaten it.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Put the hunting mechanism in your </font></font><code>aTerribleThingToDO()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">trunk. </font><font style="vertical-align: inherit;">Similar to the </font></font><code>eatLight()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">method, return </font></font><code>true</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">a value if it survived, i.e. it was not eaten by another hunter during the hunt, otherwise it should be the return value </font></font><code>false</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">. </font><font style="vertical-align: inherit;">It </font></font><code>run()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">now calls the hunting and photosynthesis methods continuously until one of them returns a false value.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">If the hunt is successful, the pig will confess by relaying the </font></font><code>"Bless me, Father, for I have sinned."</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">message.</font></font></p>
<hr class="solid" style="border-top: 1px solid orange;">
<h4><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Improved parallelization model - 2 points</font></font></h4>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Note that with the </font></font><code>openArea</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">up and down registration, we create a critical stage, because within this, the pigs have a way to see each other and influence each other's status. </font><font style="vertical-align: inherit;">However, no writing operations take place in these stages, as they are just watching and sleeping. </font><font style="vertical-align: inherit;">When hunting, dropping takes place later, hidden. </font><font style="vertical-align: inherit;">Similarly, the result of photosynthesis takes place on the way home. </font><font style="vertical-align: inherit;">Because of this, if you call the methods in the right order, you don't need huge blocks that implement mutual exclusion.</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">If all the ropes break and you cannot implement the given function without a lock, use explicit locks using the </font></font><code>ReentrantLock</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">class! </font><font style="vertical-align: inherit;">Use the related </font></font><code>Condition</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">signaling system if necessary!</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Help: in the case of speech, </font><font style="vertical-align: inherit;">use the lock for </font></font><code>gimmeTheMike</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">the name, for birth . </font></font><code>labourWard</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">In the latter case, use condition </font></font><code>birthControl</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">as name. </font><font style="vertical-align: inherit;">Use this to signal the end of the simulation after the correct number of births!</font></font></p>
<p style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">When stopping, your program should not crash or throw an exception. </font><font style="vertical-align: inherit;">Don't use your own flag variable either, it's unnecessary. </font><font style="vertical-align: inherit;">Instead, use the </font></font><code>pigPool.shutDownNow()</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">interrupt flag flipped by him to stop the pigs that are still alive. </font><font style="vertical-align: inherit;">That's when they stop whatever they're doing and be proud of themselves. </font><font style="vertical-align: inherit;">They communicate this to the world by </font></font><code>"Look on my works, ye Mighty, and despair!"</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">shouting.</font></font></p>
<hr class="solid" style="border-top: 5px solid red;">
<h1 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Diligent task (+3p)</font></font></h1>
<h3 style="text-align: center;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">CyclicBarrier</font></font></h3>
<h4 style="text-align: center;; color: gray"><i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Difficulty: I WANT MY MOMMY!!!</font></font></i></h4>
<hr class="solid" style="border-top: 5px solid red;">
<div id="goog-gt-tt" class="skiptranslate" dir="ltr"><div style="padding: 8px;"><div><div class="logo"><img src="./2022-23-1-assignment2_en_files/translate_24dp.png" width="20" height="20" alt="Google Translate"></div></div></div><div class="top" style="padding: 8px; float: left; width: 100%;"><h1 class="title gray">Original text</h1></div><div class="middle" style="padding: 8px;"><div class="original-text"></div></div><div class="bottom" style="padding: 8px;"><div class="activity-links"><span class="activity-link">Contribute a better translation</span></div><div class="started-activity-container"><hr style="color: #CCC; background-color: #CCC; height: 1px; border: none;"><div class="activity-root"></div></div></div><div class="status-message" style="display: none;"></div></div><p><i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Soon...</font></font></i></p><div class="goog-te-spinner-pos"><div class="goog-te-spinner-animation"><svg xmlns="http://www.w3.org/2000/svg" class="goog-te-spinner" width="96px" height="96px" viewBox="0 0 66 66"><circle class="goog-te-spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div></div></body></html>