Golf Ball Allocation Monitor - Lab Exercise

Part 1

At a golf club, players can hire golf balls for their game from the club and return them to the club after use. The better players, who tend not to lose any balls, only hire one or two. The less experienced players hire more balls, so that they will have spares during the game in case of loss. They are, however, required to buy replacements for the lost balls so that they return the same number that they originally hired. The golf balls are kept by the club groundsman, who turns out to be a techie. He decides to treat the players as Java threads and to write a monitor to allocate golfballs to players, if available, or to delay the players if insufficient are available.

Simple Allocation Strategy

Unable to load applet

To Do

1a) Provide an implementation for the Golf ball allocator monitor class:

interface Allocator {
    public void get(int n); // get n golballs
    public void put(int n); // return n golfballs
class SimpleAllocator implements Allocator{

    public SimpleAllocator(int n) { ... }

    synchronized public void get(int n) {...}

    synchronized public void put(int n) {...}


1b) Annotate the allocator monitor with the invariant and with the condition associated with each notify().

Part 2