Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP!!!!!!! FileDisplay Class Write a class named FileDisplay with the following methods: Constructor: The classs constructor should take the name of a file as

JAVA HELP!!!!!!!

FileDisplay Class Write a class named FileDisplay with the following methods:

Constructor: The classs constructor should take the name of a file as an argument.

displayHead: This method should display only the first five lines of the files contents. If the file contains less than five lines, it should display the files entire contents.

displayContents: This method should display the entire contents of the file, the name of which was passed to the constructor.

displayWithLineNumbers: This method should display the contents of the 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. Next, create another Java class named FileDisplayRun which:

Create an endless loop that accepts a number and validate value is from 1 to 4.

If (opt == 4) System.exit(0);

Request a file name.

Use code like this to verify that the file exists before instantiating the FileDisplay object:

fileNameIn = keyboard.nextLine();

//make sure the file exists

file = new File(fileNameIn);

if (file.exists())

{

//create instance of the FileDisplay class

fd = new FileDisplay(fileNameIn);

while(true) {

System.out.println(,,, // prompt user with a little menu opt = keyboard.nextInt();

switch (opt)

{

case 1: fd.displayHead(); break;

case 2: fd,displayComtents(); break;

case 3: fd.displayWithLineNumbers();break;

case 4: System.exit(0);

}

}

} else {

System.out.println("The file " + fileNameIn + " does not exist.");

}

Hint: The text file should be placed in the folder containing the Chapter5 folder.

Grading criteria follow: Only Java features introduced through the current textbook chapter should be utilized to complete the exercise. No Try-Catch blocks will be allowed. The throws IOException should be used on method header, where needed. Variables and method names should be named using camel-case. Variables should be nouns (names) and methods names should begin with a verb (action) word. Class names should always begin with a capital letter and only one class per source file. Your FileDisplay.java should be written per the given Class diagram. Your FileDisplayRun.java should be written as described above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions