You have been given a DangerousAnimal to care for. To keep it happy you must ensure that it is stroked every 3 seconds (make the first stroke sooner to be on the safe side). If it growls then you must get some food and feed it within 5 seconds (still stroking it as required). Unfortunately getting the food sometimes takes more than 5 seconds, in which case you must immediately run away (within 0.5 second) or it will eat you instead.
You are provided with the DangerousAnimal class (DangerousAnimal.java), an instance of which represents your dangerous animal. The DangerousAnimal has the following methods:
// stroke the animal
public void stroke();
// get the AsyncEvent that is fired each time it "growls"
public AsyncEvent getGrowlEvent();
// get food for the animal
public DangerousAnimal.Food getFood();
// give food (from getFood()) to the animal
public void feed(DangerousAnimal.Food foor);
// run away from the animal
public void runAway();
Note: you don't need to understand how the DangerousAnimal class works - but you are welcome to look at it and try! (Don't change it, though - I will test you application against the original class.)
Write an application using RTSJ that:
When you run your application, the DangerousAnimal class will generate a file DangerousAnimalHistory.txt; when you run away (or fail to stroke or feed it) the application will terminate. Here is a sample log file from a working application: DangerousAnimalHistory1.txt for comparison (some of its behaviour is random, so you won't get exactly the same result).
(Hopefully it is reasonably obvious that the same principles would apply to e.g. interfacing to a device driver or a process control system :-)
You should submit:
Submission is via CW, coursework 234. Make sure that you submit all of the above in one go (i.e. a directory containing all of them, a zip file, or all files at once). To use CW log into your "home" CS UNIX machine and type "cw" for usage information.
The coursework submission deadline in 5pm, Friday 11th December.
Chris Greenhalgh
2009-11-06