Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Make a FileStats class that represents a file. This class will have the ability to calculate the number of lines in that file

IN JAVA

Make a FileStats class that represents a file. This class will have the ability to calculate the number of lines in that file and the ability to search through the file.The getNumMatchingWords method will take a bit of text and determine how many lines contain that text. Make the comparison not care about case.

///////////////////////////////////// Given Files \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

  • bill-of-rights.txt
  • dictionary.txt
  • romeo-and-juliet.txt

FileStatsDemo.java

import java.io.FileNotFoundException; public class FileStatsDemo { public static void main(String[] args) throws FileNotFoundException { FileStats billOfRights = new FileStats("bill-of-rights.txt"); FileStats romeoAndJuliet = new FileStats("romeo-and-juliet.txt"); FileStats dictionary = new FileStats("dictionary.txt"); System.out.println("Num lines in Bill of Rights: " + billOfRights.getNumLines()); System.out.println("Num lines in Romeo and Juliet: " + romeoAndJuliet.getNumLines()); System.out.println("Num lines in dictionary: " + dictionary.getNumLines()); System.out.println("-- Bill of Rights Test --"); System.out.println("'the' count: " + billOfRights.getNumMatchingWords("the")); System.out.println("'no' count: " + billOfRights.getNumMatchingWords("no")); System.out.println("'rights' count: " + billOfRights.getNumMatchingWords("rights")); System.out.println("-- Romeo and Juliet Test --"); System.out.println("'Romeo' count: " + romeoAndJuliet.getNumMatchingWords("ROMEO")); System.out.println("'Juliet' count: " + romeoAndJuliet.getNumMatchingWords("juliet")); System.out.println("'end' count: " + romeoAndJuliet.getNumMatchingWords("end")); System.out.println("'emoji' count: " + romeoAndJuliet.getNumMatchingWords("emoji")); } } 

/////////////////////////////Required Output\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Num lines in Bill of Rights: 65 Num lines in Romeo and Juliet: 5268 Num lines in dictionary: 21882 -- Bill of Rights Test -- 'the' count: 29 'no' count: 17 'rights' count: 2 -- Romeo and Juliet Test -- 'Romeo' count: 304 'Juliet' count: 185 'end' count: 95 'emoji' count: 0 

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

Students also viewed these Databases questions