Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Intro to Java help?) Write a static method named textCount that takes a Scanner representing a file as a parameter and that reports various statistics

(Intro to Java help?)

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 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,

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_2

Step: 3

blur-text-image_3

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago