Write a program that asks a user for a file name and prints

Assignment Help JAVA Programming
Reference no: EM13161798

Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.

the FileCounter class.

import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFileChooser;

/**
   This class prints a report on the contents of a file.
*/
public class FileAnalyzer
{
   public static void main(String[] args) throws IOException
   {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
      {

        FileReader reader = new FileReader(chooser.getSelectedFile());
        Scanner fileIn = new Scanner(reader);
        FileCounter counter = new FileCounter();
        counter.read(fileIn);
        fileIn.close();
        System.out.println("Characters: " + counter.getCharacterCount());
        System.out.println("Words: " + counter.getWordCount());
        System.out.println("Lines : " + counter.getLineCount());
    }
   }
}
import java.util.Scanner;
/**
   A class to count the number of characters, words, and lines in files.
*/
public class FileCounter
{
   /**
    * instance variables
    */
   //your code here...

   /**
      Constructs a FileCounter object.
   */
   public FileCounter()
   {
     //Your code here . . .

   }

   /**
      Processes an input source and adds its character, word, and line
      counts to this counter.
      @param in the scanner to process
   */
   public void read(Scanner in)
   {
      while (in.hasNextLine())
      {
          String line=in.nextLine();
          //Your code here. . .


      }
   }

   /**
      Gets the number of words in this counter.
      @return the number of words
   */
   public int getWordCount()
   {
      //Your code here. . .

   }

   /**
      Gets the number of lines in this counter.
      @return the number of lines
   */
   public int getLineCount()
   {
     //Your code here . . .

   }
   /**
      Gets the number of characters in this counter.
      @return the number of characters
   */
   public int getCharacterCount()
   {
     //Your code here . . .
   }

}

 

 

Reference no: EM13161798

Questions Cloud

Colonists to publically criticize slavery : The first group of colonists to publically criticize slavery were the:  Puritans.  Quakers.  farmers.  indentured servants.
Explain the relationships and related to each other : Interpret and explain the use case diagram in the Figure 1: book new edition p. 149. Explain the various roles of those using the system and what functions each role requires. Explain the relationships and how the use cases are related to each other.
Entrepreneurial intensity in the revolutionary sector : Companies should strive to position its EI (entrepreneurial intensity) in the revolutionary sector of the frequency-degree entrepreneurial grid in order to achieve best fit with its internal and external environments.
Design your application according to the considerations : Design your application according to the considerations described above.  For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are
Write a program that asks a user for a file name and prints : Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.
The rpn calculator program : The RPN calculator program should read the RPN expression as an entire line from stdin.Input will consist of a single line. After completing the evaluation of the expression, the program should print the contents of the entire stack, starting with th..
Function which correctly sorts three : Write an x8086 HLA Assembly language program that implements a function which correctly sorts three parameters and returns a boolean value in AL which should be set to true if any swaps were performed to sort the sequence in increasing order.
Cashregister class that can be used with the retailitem clas : Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.
Shows the users name and program name : Java program, the program has a page that shows the users name and program name. a second jpanel that shows 4 buttons (circle square rectangle and oval) the problem i am having is that my program is not dropping where i click and the shapes are not s..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Java application to display multiple choice questions

Write down the application which displays series of TEN(10) multiple choice questions: questions must cover all the Java. Each question must have four possible answers and only one answer must be correct.

  Solving programming problems

Write a computer program that will figure out the total of an order when given the amount of the order ($1000) and a sales tax rate of eight percent.

  The williamsburg women''s club

The Williamsburg Women's Club offers scholarships to local high school students who meet any of several criteria. Write an application that prompts the user for a student's numeric high school grade point average (for example, 3.2), the student's num..

  One-dimensional array to solve the

In C#, Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who gros..

  Write java code to read integers from an input file

write java code to read integers from an input file and write only the odd numbers to an output file. the two file names will be provided on the command line as the input file followed by the output file.

  Create a recursive factorial program

Assignment 1: Create a recursive factorial program that prompts the user for an integer  N  and writes out a series of equations representing the calculation of  N !. For example, if the input is 4, the output could be:

  Design and implement a small and simple email server

Design and implement a small and simple email server

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Communication with an smtp server

Develop a graphical user interface based java program that can communicate with a real SMTP email server for sending emails

  Create the class airplane

Your missions is to create the class Airplane. Each Airplane object should store the following information (fields):

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd