The AdaptingMenu class diagram is presented in Figure 7.1.

The diagram shows that, in addition to the constructor, the class
supplies new actions to enable and to disable a menu option; as
well as an overloaded offerMenuAsInt action. It also suggests
that it provides its own private showMenu action. The implementation
of this design as far as the end of the constructor is as follows.
0001 // Filename Menus/AdaptingMenu.java.
0002 // Providing an extended menu which can change
0003 // the options which it presents.
0004 //
0005 // Written for JFL book Chapter 7 see text.
0006 // Fintan Culwin, v0.1, January 1997.
0007
0008 package Menus;
0009
0010 public class AdaptingMenu extends Menus.BasicMenu {
0011
0012 boolean inUse[];
0013 char optionKey[];
0014
0015 public AdaptingMenu( String title,
0016 String options[],
0017 String prompt) {
0018
0019
0020 super( title, options, prompt);
0021 inUse = new boolean[ options.length];
0022 optionKey = new char[ options.length];
0023 } // End AdaptingMenu constructor.
This class introduces two additional iterative data attributes:
a boolean array called
inUse which indicates
which options are currently in use and a character
array called optionKey
which indicates which menu key is associated with each option.
The use made of these arrays will be described below.
The three arguments of the constructor are used in exactly the
same way as the three arguments of the BasicMenu
constructor. The first action of the AdaptingMenu
constructor is to call the BasicMenu
constructor passing on the three arguments. The remaining actions
of the constructor are to create the two arrays, inUse
and optionKey, with sizes
determined by the number of elements in the options
argument array. The state of the data attributes of an instance
of the AdaptingMenu class,
using the same example values as were used for the BasicMenu
class immediately after it has been constructed, is shown in Figure
7.2.

The default value of a boolean
variable is false and
so all values in the inUse
array are shown to be false. This will be interpreted to mean
that upon construction none of the menu options are active. The
default value of a character variable is the null character, shown
as ''. The use of the optionKey array will be described
below.
7.2 The enableMenuOption(), disableMenuOption() and showMenu() actions.