Write a class name FileDisplay with the following methods: Constructor: takes the name of a file as an argument displayHead: displays only the first five lines of the file’s contents. If the file...


Write a class name FileDisplay with the following methods:




  • Constructor:  takes the name of a file as an argument

  • displayHead:  displays only the first five lines of the file’s contents.  If the file contains less than 5 lines, it should display the file’s entire contents.

  • displayContents:  displays the entire contents of the file, the name of which was passed to the constructor.

  • writeNew:  displays the contents of a file, the name of which was passed to the constructor.  Each line should be preceded with a line number followed by a colon.  The line numbering should start at 1.  As each line is displayed it should also be written to a new file, the name of which is passed in as a parameter.


I have provided a test file called “testfile.txt”.  I have also provided a driver for the application called “filedisplaytest.java”.  This file is complete and should not be altered.


Test File:


This is line one.
This is line two.
This is line three.
This is line four.
This is line five.
This is line six.
This is line seven.



public class FileDisplayTest<br>{<br>public static void main (String [] args) throws IOException<br>{<br>// Create an instance of the FileDisplay object.<br>FileDisplay fd = new FileDisplay(

Extracted text: public class FileDisplayTest { public static void main (String [] args) throws IOException { // Create an instance of the FileDisplay object. FileDisplay fd = new FileDisplay("TestFile.txt"); // Test the displayHead method. System.out.println("File Head:"); fd.displayHeadlli // Test the displayContents method. System.out.println("\nFile Contents:"); fd.displayContents(); // Test the displayWithLineNumbers method. System.out.println("\nFile Contents with Line Numbers:"); //fd.displayWithLineNumbers(); fd.writeNew("TestFileNew.txt"); } }
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here