// should make visitors self contained // should use int instead of Integer Holding_company { traversal allSalaries(CountingVisitor, SummingVisitor) { to Salary; } } CountingVisitor { before Employee (@ total = new Integer(total.intValue() + 1) ; @) } SummingVisitor { before Salary (@ total = total.add(host.get_v()); @) } Currency { (@ // a constructor to make things a little easier... public Currency(int d) { dollars = new Integer(d); } public Currency add(Currency c) { return new Currency(this.get_dollars().intValue() + c.get_dollars().intValue()); } @) } Main { (@ static public void main(String args[]) throws Exception { Holding_company comp = Holding_company.parse(System.in); CountingVisitor count = CountingVisitor.parse("0"); SummingVisitor sum = SummingVisitor.parse("0"); // CountingVisitor count = // new CountingVisitor(new Integer(0)); // SummingVisitor sum = // new SummingVisitor(new Currency(new Integer(0))); comp.allSalaries(count,sum); System.out.println("employee count " + count.get_total()); System.out.println("total salaries " + sum.get_total().get_dollars()); int r = sum.get_total().get_dollars().intValue(); if (r == 300) System.out.println("SUCCESS"); else System.out.println("FAILURE"); } @) }