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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. 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!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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