Java Code Write a program in which you create a class called TextFileReader. The TextFileReader class must contain an instance variable consisting of an array of Strings 100 elements long. TextFileReader should have two constructors: a default constructor and a constructor that takes a String argument, which represents the name of a text file to be opened and read into the array of Strings. The first (default) constructor does not really do anything. If the second constructor is used, it will open the file and read the contents of the file into the array of Strings as follows: fill the array by having your program read one line of the file into each string until you have filled the array. Once the array is full, you may stop reading the input file. Add a member function contents(), which will convert the array of Strings into a single StringBuffer, which is then returned to the calling program so that it may be displayed. Add a second member function display(), which prints the array to standard output using the format line #: , where # is the actual line number and is the stored string. [You can use the array counter for the # value.] Do not forget that line numbers for the output should start with 1, not 0. Now, create a second class TextFileReaderDemo, which contains a main() method used to test TextFileReader. Create an instance of TextFileReader using the second constructor, and then call contents() to obtain the file’s text. Display the file’s contents to standard output. Finally, call display() to output the file’s text together with line numbers, as stated in the display() requirements. TextFileReaderDemo should use command-line arguments to obtain the text file name supplied to the TextFileReader constructor. Test file with exceprt.txt There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge. In another moment down went Alice after it, never once considering how in the world she was to get out again. The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled `ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 1CP: In previous chapters, you have created programs for the Greenville Idol competition. Now create a...
icon
Related questions
Question

Java Code

Write a program in which you create a class called TextFileReader. The TextFileReader class must contain an instance variable consisting of an array of Strings 100 elements long.

TextFileReader should have two constructors: a default constructor and a constructor that takes a String argument, which represents the name of a text file to be opened and read into the array of Strings. The first (default) constructor does not really do anything. If the second constructor is used, it will open the file and read the contents of the file into the array of Strings as follows: fill the array by having your program read one line of the file into each string until you have filled the array. Once the array is full, you may stop reading the input file.

Add a member function contents(), which will convert the array of Strings into a single StringBuffer, which is then returned to the calling program so that it may be displayed.

Add a second member function display(), which prints the array to standard output using the format line #: <string>, where # is the actual line number and <string> is the stored string. [You can use the array counter for the # value.] Do not forget that line numbers for the output should start with 1, not 0.

Now, create a second class TextFileReaderDemo, which contains a main() method used to test TextFileReader. Create an instance of TextFileReader using the second constructor, and then call contents() to obtain the file’s text. Display the file’s contents to standard output. Finally, call display() to output the file’s text together with line numbers, as stated in the display() requirements.

TextFileReaderDemo should use command-line arguments to obtain the text file name supplied to the TextFileReader constructor.

Test file with exceprt.txt

There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge. In another moment down went Alice after it, never once considering how in the world she was to get out again. The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled `ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.

Expert Solution
steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage