public class Menu
1: //Menu.java
2: //A Menu class for console programs
4: import java.io.*;
6: public class Menu
7: {
8: //Replace this comment with any private data
9: //members and/or private helper functions you need.
12: //Default constructor
13: //Gives the menu a default tile of "Empty Menu"
14: public Menu()
15: {
16: //Body of default constructor
17: }
20: //Constructor with title
21: //Gives the menu the title supplied as the input parameter.
22: //If the title is too long, displays an error message and
23: //gives the menu a default title of "Empty Menu".
24: public Menu(String menuTitle)
25: throws IOException
26: {
27: //Body of non-default constructor
28: }
31: //Sets or changes the title of a menu to the text of the
32: //input parameter. Displays an error and pauses if the
33: //title is too long (> 60 characters), and leaves title
34: //unchanged in this case.
35: public void setTitle(String menuTitle) throws IOException
36: {
37: //Body of setTitle method
38: }
41: //Adds an option to the menu and gives it the next
42: //available option number. Displays an error and pauses
43: //if the maximum number of options (20) is exceeded or
44: //if the option is too long (> 60 characters), and leaves
45: //the menu unchanged in this case.
46: public void addOption(String option)
47: throws IOException
48: {
49: //Body of addOption method
50: }
53: //Displays the menu more or less centered on the screen.
54: //If the menu has no options, displays the "Empty Menu"
55: //title, a blank space and a message saying the menu has
56: //no options.
57: public void display()
58: {
59: //Body of display method
60: }
63: //Returns the choice entered by the user or a value of -1
64: //if the user fails to enter a valid choice in three tries
65: public int getChoice()
66: throws IOException
67: {
68: //Body of getChoice method
69: }
72: //Provides a short test driver for the Menu class
73: public static void main(String[] args)
74: throws IOException
75: {
76: Menu m = new Menu("A New Menu");
77: m.addOption("Quit");
78: m.addOption("Get information");
79: m.addOption("Do something");
80: m.display();
82: int menuChoice;
83: do
84: {
85: m.display();
86: menuChoice = m.getChoice();
87: switch (menuChoice)
88: {
89: case -1:
90: case 1:
91: screen.println("Program now terminating.");
92: pause();
93: break;
94: case 2:
95: screen.println("Getting information ... ");
96: pause();
97: break;
98: case 3:
99: screen.println("Doing something ... ");
100: pause();
101: break;
102: }
103: }
104: while (menuChoice != -1 && menuChoice != 1);
105: }
107: }