Can you change a Galway shuttle's receipt without touching the fare calculation?
A Galway shuttle charges two euro per booking plus three euro per ticket. The driver wants the screen to say ‘Total due’ before the price. Can you change what passengers see without touching the fare calculation?
For one ticket, add the two euro booking fee to three euro to get five euro. For three tickets, you pay two euro plus nine euro, so the total is eleven euro. The count changes, but you can use the same rule for both bookings.
Follow the booking through three blocks. Input reads a whole number and passes the ticket count to the calculation. The calculation returns a total in euro for the display to print. Giving each block a job is modular design. Each arrow labels the value passed across an interface.
The input block has passed the ticket count to the calculation. Now follow the next connection. Which value should go from the price block to the show block? Pick one answer.
Read the input and store the count, three, in tickets. Pass tickets to the supplied price block. It adds two to three times three, so you store eleven in total. Pass total to the supplied show block, which prints the euro sign followed by eleven.
Now you enter five tickets. Follow the count into the same price block, then send its result to the original display. What appears on screen? Pick one answer.
The input and price functions stay the same. Show prints the euro amount. Show receipt takes the same number and adds the words ‘Total due’. At the bottom, read three tickets and calculate the fare as before. Change only the display call. The screen now shows ‘Total due: eleven euro’.
On the left, the fare code builds a shared message. If the display expects that message in a particular format, changing the format can break it. Separate headings leave that dependency in place. On the right, the fare code returns a number, so the display can choose its own wording.
If the question says ‘Explain how modular design is used in this program’, name each block's job and say what value is passed between blocks. Then use the replacement as evidence: the output wording changes, while the price function still returns the same number.