A06

Due Date: Thursday, March 5
File(s) to be submitted: TextItems.java
Sample Output: SampleOutput.html
Starter Files:


SUBMIT   /   Check

Creating the TextItems Class (File I/O, Exceptions, Lists)

Summary

Implement the TextItems class. This class is designed to show text one page at a time. It consists of a constructor and a method to display an item. The text is drawn from a file when a TextItems object is constructed.

In TextItems create a private class Item that holds the name and contents of the text item.

Use List objects to hold the contents of each Item and all the Items of the TextItem.

Details

The TextItems class encapsulates an object that holds and displays pre-formatted text. Each block of text has a name that the client uses to request the block, and it may include "pauses" where the computer will stop and wait for the user to press the enter key.

The constructor takes two arguments: a file name and a Scanner. For example:

TextItems ti = new TextItems("MiniItems.txt", KBD);
The Items come from the named file. The Scanner's use is described below.

The text in the named file is in this format:

For example, the file MiniItems.txt is as follows:
First Item
First line of first item
Second line of first item
--------------------------------------------------------------------------------
Second Item
First line of second item

Third line of second item
--------------------------------------------------------------------------------
It consists of two items, one named "First Item" and the other named "Second Item". The first item has two lines, while the second has three (the middle line being blank). When the client asks to display "First Item"
ti.displayItem("First Item");
the screen should show
First line of first item Second line of first item
When the client asks for the "Second Item" the screen would show
First line of second item Third line of second item

Some items will contain a line of 80 at signs (@). Those lines are not to be printed, but instead signify that the print-out should pause (with a brief message, such as "...press enter...") and wait for the user to press the enter key.

Note: this is what the Scanner argument to the constructor is for. That is the Scanner you need to listen on for the user to press enter.
(The line must have exactly 80 at signs or else it's just another line to be printed.) For full credit that's just what your code should do.

Further Requirements

Hints


SUBMIT   /   Check