Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implementing a class? I am currently trying to implement the TestStatistics.java class that works with the ProccessText.java. I am confused on how to refence the

Implementing a class?

I am currently trying to implement the TestStatistics.java class that works with the ProccessText.java. I am confused on how to refence the file name and creating the constructor.

image text in transcribed

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class ProccessText {

public static void main(String[] args){

String filename="parsing1.txt";

//Scanner scan= new Scanner(filename);

File testFile = new File(filename);

try{

String newLine = "";

Scanner fScan = new Scanner(testFile );

System.out.println(" Contents of \"" + filename + "\": ");

while (fScan.hasNextLine()) {

String line = fScan.nextLine();

Scanner lScan = new Scanner(line);

System.out.println(fScan.nextLine());

// while (lScan.hasNext()) {

//

// System.out.println(lScan.next());

// }

lScan.close();

}

fScan.close();

} catch (FileNotFoundException errorObject) {

System.out.println("File \"" + filename + "\" could not be opened.");

System.out.println(errorObject.getMessage());

//System.exit(ERROR_CODE);

}

}

}

public class TextStatistics implements TextStatisticsInterface{

int numChar;

int numWords;

int numLine;

int numLetter;

int wordLength;

double averageLength;

@Override

public int getCharCount() {

// TODO Auto-generated method stub

return 0;

}

@Override

public int getWordCount() {

// TODO Auto-generated method stub

return 0;

}

@Override

public int getLineCount() {

// TODO Auto-generated method stub

return 0;

}

@Override

public int[] getLetterCount() {

// TODO Auto-generated method stub

return null;

}

@Override

public int[] getWordLengthCount() {

// TODO Auto-generated method stub

return null;

}

@Override

public double getAverageWordLength() {

// TODO Auto-generated method stub

return 0;

}

}

4.2 Task 2: Implement TextStatistics.java An instantiable class that reads a given text file, parses it, and stores the generated statistics Implement the Interface Your TextStatistics class must implement the given TextStatisticsInterface (don't modify the interface, it just provides a list of methods that your class must include) To implement an interface, you must modify your class header as follows public class TextStatistics implements TextStatisticsInterfacet //Your class goes here Adding implements TextStatisticsInterface will cause an error in Eclipse. Select the quick fix option to "Add unimplemented methods" and it will stub out the required methods for yol Instance variables Include a reference to the processed File. Include variables for all of the statistics that are computed for the file. Look at the list of accessor methods in the TextStatisticsInterface to determine which statistics will be stored Constructor Takes a File object as a parameter. The constructor should open the file and read the entire file line-by-line, processing each line as it reads it Note: Your implementation must read through each file once. By the end of the constructor, the TextStatistics object should have collected all of its statistics and calls to its accessor methods will simply return the stored values Your constructor needs to handle the FileNotFoundException that can occur when the File is opened in a Scanner. Use a try-catch statement to do this. Don't just throw the exception

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions