class TextItems
1: //TextItems.java
2: //A TextItems class for console programs
4: import java.io.*;
6: class TextItems
7: {
9: //Private data and/or types and/or helper functions go here
12: //********************************************************************
13: TextItems()
14: {
15: //Body of default constructor goes here
16: }
19: //********************************************************************
20: TextItems(/* in */ String fileName)
21: throws IOException
22: {
23: //Body of non-default constructor goes here
24: }
26: //********************************************************************
27: public void displayItem(/* in */ String title)
28: throws IOException
29: {
30: //Body of display routine goes here
31: }
35: //********************************************************************
36: //Test Driver
37: public static void main(String[] args)
38: throws IOException
39: //Post:
40: //The user has had an opportunity to load in zero or more files of
41: //textitems and display zero or more of the text items in each of
42: //those files.
43: {
44: final String PROGRAM_DESCRIPTION =
45: "\nThis program demonstrates use of the " +
46: "TextItems class to display \"text items\". " +
47: "\nBe sure that you know what a file of " +
48: "such items looks like, and that you have " +
49: "\nat least one available, before you attempt " +
50: "to use this program. ";
52: final String PROMPT_FOR_FILE =
53: "\n>>>>> Enter full name of file containing text items, \n" +
54: ">>>>> or just press ENTER to quit:";
56: final String PROMPT_FOR_TITLE =
57: "\n===== Enter title of text item to display, or \n" +
58: "===== just press ENTER to quit displaying items:";
60: try
61: {
62: screen.println(PROGRAM_DESCRIPTION);
64: screen.println(PROMPT_FOR_FILE);
65: String fileName = keyboard.readLine();
66: while (fileName.length() != 0)
67: {
68: TextItems itemList = new TextItems(fileName);
70: screen.println(PROMPT_FOR_TITLE);
71: String title = keyboard.readLine();
72: while (title.length() != 0)
73: {
74: itemList.displayItem(title);
75: screen.println(PROMPT_FOR_TITLE);
76: title = keyboard.readLine();
77: }
78: screen.println(PROMPT_FOR_FILE);
79: fileName = keyboard.readLine();
80: }
81: }
82: catch (Exception e)
83: {
84: System.out.println("Program terminating with error:\n" +
85: e.toString());
86: }
87: }
89: } //End of TextItems class