The last question was just a map question. You can reasonably assume that getTransaction returns null when there is no input. Thus you repeatdely invoke getTransaction to get a Transaction object and use it to update a map. // Reads Transactions from scan (using getTransaction) // and then combines Transactions into a Map that is // created in computeSpending and then returned to the caller. public Map computeSpending( Scanner scan ) { Map result = new HashMap( ); while( true ) { Transaction t = getTransaction( scan ); if( t == null ) // No more input return result; String person = t.getPerson( ); Integer spent = result.get( person ); if( spent != null ) result.put( person, spent + t.getAmount( ) ); else result.put( person, t.getAmount( ) ); } }