public interface AFinancialHistory { // Transaction recording public void receive(int amount, String source); public void spend(int amount, String reason); // Inquiries public int cashOnHand(); public int totalReceivedFrom(String source); public int totalSpentFor(String reason); } public class FinancialHistory implements AFinancialHistory { private int cashOnHand; private java.util.Hashtable incomes, expenditures; // Transaction recording public void receive(int amount, String source) { incomes.put(source, new Integer(this.totalReceivedFrom(source) + amount)); this.cashOnHand = this.cashOnHand + amount; } public void spend(int amount, String reason) { expenditures.put(reason, new Integer(this.totalSpentFor(reason) + amount)); this.cashOnHand = this.cashOnHand - amount; } // Inquiries public int cashOnHand() { return this.cashOnHand; } public int totalReceivedFrom(String source) { return incomes.containsKey(source) ? ((Integer) incomes.get(source)).intValue() : 0; } public int totalSpentFor(String reason) { return expenditures.containsKey(reason) ? ((Integer) expenditures.get(reason)).intValue() : 0; } // Instance creation public FinancialHistory(int amount) { this.cashOnHand = amount; this.incomes = new java.util.Hashtable(); this.expenditures = new java.util.Hashtable(); } } public interface ADeductibleHistory extends AFinancialHistory { // Transaction recording public void spendDeductible(int amount, String reason); public void spend(int amount, String reason, int deductibleAmount); // Inquiries public int totalDeductions(); } public class DeductibleHistory extends FinancialHistory implements ADeductibleHistory { private int deductibleExpenditures; // Transaction recording public void spendDeductible(int amount, String reason) { this.spend(amount, reason); this.deductibleExpenditures = this.deductibleExpenditures + amount; } public void spend(int amount, String reason, int deductibleAmount) { this.spend(amount, reason); this.deductibleExpenditures = this.deductibleExpenditures + deductibleAmount; } // Inquiries public int totalDeductions() { return this.deductibleExpenditures; } // Instance creation public DeductibleHistory(int amount) { super(amount); this.deductibleExpenditures = 0; } } public class RunFinancialHistory { public static void main(String [] args) { DeductibleHistory h = new DeductibleHistory(100); System.out.println(h.cashOnHand()); } }