Java: Write a static method named textCount that takes a Scanner representing a file as a parameter and that reports various statistics about the file.  In particular, your method should report the number of lines in the file, the total number of characters (not counting any new-line \n characters) in the file, and the length and text of the longest line.  You may assume that the input file has at least one line of input. For example, if the file contains the following text: Twas brillig and the slithy toves did gyre and gimble in the wabe. All mimsey were the borogroves, and the mome raths outgrabe.    "Beware the Jabberwock, my son, the jaws that bite, the claws that catch, Beware the JubJub bird and shun the frumious bandersnatch." The program would find that there are 9 lines (blank lines count), a total of 254 characters in the file (33 on the first line, 32 on the next line, 31 on the next line, 28 on the next, 0 on the next, etc) and that the longest line is the one that begins with "the jaws that bite".  The method would produce the following output: Total lines            = 9 Total chars            = 254 Length of longest line = 41 Longest line           = the jaws that bite, the claws that catch

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java: Write a static method named textCount that takes a Scanner representing a file as a parameter and that reports various statistics about the file.  In particular, your method should report the number of lines in the file, the total number of characters (not counting any new-line \n characters) in the file, and the length and text of the longest line.  You may assume that the input file has at least one line of input.

For example, if the file contains the following text:

Twas brillig and the slithy toves

did gyre and gimble in the wabe.

All mimsey were the borogroves,

and the mome raths outgrabe.

  

"Beware the Jabberwock, my son,

the jaws that bite, the claws that catch,

Beware the JubJub bird and shun

the frumious bandersnatch."

The program would find that there are 9 lines (blank lines count), a total of 254 characters in the file (33 on the first line, 32 on the next line, 31 on the next line, 28 on the next, 0 on the next, etc) and that the longest line is the one that begins with "the jaws that bite".  The method would produce the following output:

Total lines            = 9

Total chars            = 254

Length of longest line = 41

Longest line           = the jaws that bite, the claws that catch,

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Constants and Variables
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education