Consider a city where there train network has two zones. Zones impact the cost of a journey. The more zones crossed the more the journey costs. Each passenger has to swipe their ticket to indicate the end of their journey. Within this network there is a station that gets quite busy at the end of the day.

“Here is a sketch of our train station (the dark triangles are the ticket readers):”

The trouble is that this particular station sits in an increasingly popular area. As each month goes by the number of passengers alighting here goes up.

The question is: by changing only one thing how can we maximise the throughput of the alighting passengers?

Send your answers to p2@thoughtworks.com, once again the first person with the best answer wins.

Last Issue’s Puzzle

The Java Finally puzzle has joint-winners: Anand Krishnaswamy and Alex Ong. Alex SMS’d his answer within minutes of the issue being published but didn’t provide the why. Shortly afterwards Anand sent us this answer explaing why but didn’t tell us the answer.

The spec says that all returns will attempt to return control to caller. So in the catch block the return attempts to return control by copying the to-be-returned value to the stack & the proceeds to execute finally (if found). The finally doesn’t return anything. It merely sets the value of a local variable (which is a primitive type) which has no impact on the value copied on to the activation record. Hence, if the returned value is a primitive type or immutable (string) then there is no impact to alterations done in the finally.

In the 2nd example, the return type is a user defined type & hence the reference is set on the AR before the finally is attempted. The finally alters the contents of the reference [and] hence that is reflected in the caller. To verify this, alter the finally in the 2nd example as follows:

finally {
marketEdge = new MarketEdge();
marketEdge.value = 99;
}

Since the reference is altered from the one on the AR, changes are not reflected in the object being returned.

The answer to Exhibit A is 30 and Exhibit B is 50.

Congratulations to Anand and Alex. You’re prize is a free copy of What You Need to Know About Dates and Times in Computing. Thanks to everyone else who responded.”