public class TextItems
extends java.lang.Object
Any textfile containing text items must contain at least one text item. Any such file and each text item in it must be formatted according to the following rules:
All lines of text from the beginning of the file down to the first line consisting of 40 equal signs will be ignored. Thus one or more lines that serve to identify file content to a human reader of the file may be placed before this line. Such a line of 40 equal signs must be left-justified. A left-justified line of 40 equal signs looks like this:
========================================
The first line of each text item must be its "title", i.e., the exact string that will be used by the program to access that particular text item for display. The title is not displayed when the text item is displayed; it is used solely for identifying the item. There must be no leading or trailing spaces in the title.
Each text item must be terminated by a line of exactly 40 dashes (hyphens) which is not regarded as part of the item itself (and is therefore not displayed when the text item is shown on the screen). Each item-terminating line of 40 dashes must be left-justified. A left-justified line of 40 dashes looks like this:
----------------------------------------
The body of a text item may contain one or more lines consisting of exactly 40 exclamation marks (!) among the lines of "regular" text. Such a line indicates a point where the display must pause and ask the user to press Enter to continue, but the line itself is not displayed. Such a line of 40 exclamation marks must be left-justified. A left-justified line of 40 exclamation marks looks like this:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The last text item in the file must be followed immediately by an additional line of 40 equal signs like that shown above. Any text following this line in the file will also be ignored. It may thus be inferred that a file of text items will normally contain exactly two left-justified lines consisting of 40 equal signs, and there may (or may not) be text before the first one, and after the second one, with all such text being ignored by any program reading the file.
Keep all lines in a text item strictly less than 80 characters in length. In the first place, any line longer than this will likely wrap to a second line, and may not break where you'd like it to. Second, some systems (DOS/Windows, for example) seem to put an automatic line feed at the end of each line of exactly 80 characters. So, keeping lines under 80 characters in length will avoid extraneous blank lines in the output that might be introduced in this way.
Constructor and Description |
---|
TextItems()
Default constructor.
|
TextItems(java.io.InputStream inputStream)
Constructor that takes as input an object of type InputStream that
has been associated with a file of text items.
|
TextItems(java.lang.String fileName)
Constructor that takes the name of a file of text items as input.
|
Modifier and Type | Method and Description |
---|---|
void |
displayItem(java.lang.String title)
Displays the item having the title supplied as parameter, or an
error message if no item with that title is found.
|
static void |
main(java.lang.String[] args) |
public TextItems()
Error: File name must be supplied when declaring a TextItems object. Example: TextItems myTextItems = new TextItems("text_item_file.txt"); Program is now terminating.;
Pre-conditions:
None
Post-conditions:
The following error message has been displayed,
followed by a pause, and the program terminates after the user
presses Enter.
Error: File name must be supplied when declaring a TextItems object. Example: TextItems myTextItems = new TextItems("text_item_file.txt"); Program is now terminating.
public TextItems(java.lang.String fileName)
fileName
- The name of the file containing the text items to
be read in.
Pre-conditions:
fileName contains the name of a valid file of
text items.
Post-conditions:
This object contains the text items from the
input file.
If there is a problem opening or reading the file, an error will be reported and the program will terminate.
public TextItems(java.io.InputStream inputStream)
inputStream
- The InputStream object connected to in input
stream containing validly formatted text items.
Pre-conditions:
inputStream has been properly initialized.
Post-conditions:
This object contains the text items from the
input file.
If there is a problem opening or reading the file, an error will be reported and the program will terminate.
public void displayItem(java.lang.String title)
Error: <<title-that-was-not-present>> not found.
title
- The title of the text item to be displayed.
Pre-conditions:
title has been initialized. Post-conditions:
If the string in title has been identified as the title of a text item, that text item has been displayed. Otherwise, the following message has been displayed, followed by a pause:
Error: <<text-of-title-not-found>> not found.
public static void main(java.lang.String[] args)