Chapter 6 The BasicMenu class

All the programs which have been used so far have only produced output on the screen and have not required the user to input any information from the keyboard. Inputting information is much more complex than outputting information as it cannot be assumed that the user will always respond as expected to any instructions which they are given.

This chapter will introduce a BasicMenu class, instances of which can be constructed to offer a number of options and obtain a validated response from the user. In order to do this techniques for representing and manipulating single characters, and sequences of characters known as Strings, will have to be introduced. Each option presented to the user on the menu is represented as a string and as a number of options have to be presented the techniques for representing an iteration of strings will also have to be introduced. Iteration is the technical term for a repetition, either of data objects or of actions. The term iteration is preferred as an iteration can represent zero occurrences whereas a repetition implies at least one occurrence.

When the user is presented with the opportunity to respond to the menu it cannot be assumed that they will provide a valid input. Should this happen they will have to be informed that their input is not acceptable and be allowed to respond again. Thus the program will have to iterate a sequence of actions and the techniques for implementing this will be introduced.

The BasicMenu demonstration harneses will present a standard menu/ dispatch design which can be used as a basic design in other applications. The following chapter will illustrate such an application and extend the BasicMenu to produce a menu which can dynamically change the options which it offers.