G52CON 2008-2009: Exercise 4, Monitors in Java

Questions:

  1. A savings account is shared by several people. Each person may deposit or withdraw money from the account. The current balance in the account is the sum of all deposits to date less the sum of all withdrawals to date. The balance must never become negative. Account holders are represented as threads. A thread making a deposit never has to delay (except for mutual exclusion), but a withdrawal has to wait until there are sufficient funds.

    Develop a Java class to solve this problem (i.e. translate the monitor solution to exercise 3 into Java). In addition to the constructor, the class should have two public methods: deposit(int amount) and withdraw(int amount). Assume the arguments to deposit and withdraw are postive.