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

  Write java application to show successive element of array

Write down java application named GoTooFar which declares the array of 5 integers and stored five values in array. write try block in which you loop to show each successive element of array.

  Write down java program for furniture company

Write down a Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate price of table manufactured with chosen wood.

  Creates an array named odds

Write code that creates an array named odds and stores all odd numbers between -6 and 38 into it using a loop. Make the array's size exactly large enough to store the numbers.

  Create an abstract class named element

Part 1: Create an abstract class named Element that holds properties of elements, including their symbol, atomic number, and atomic weight. Include a constructor that requires values for all three properties and a get method for each value.

  Construct java program named collegelist

Construct a set of classes for a college to use in many student service and personnel applications. Classes you require to design include following:

  Create simulation by java language for single-server queue

Suppose that customer inter-arrival times are exponentially distributed and service times are normally distributed. Create simulation by java language for this problem and view all parametre?

  Client server monitoring system project design

client server monitoring system project design. The server adminstation can send messages to the clients and DESIGN WITH JAVA NETBEANS AND GUI.

  Implementation of memory management

Implementation of memory management

  Executing stringed musical instrument class

Create and execute a stringed musical instrument class.

  Wrappershallow and wrapperdeep

Each class is simply a wrapper class to hold a private array variable. int [] a; The default constructor for each class should initialize â??aâ??. Each class should have a toString() and equals(). Each class should have a setArray method that allows ..

  String that contains at least five letters

Write an application that prompts the user for a String that contains at least five letters and at least five digits. Continuously reprompt the user until a valid String is entered. Display a message indicating whether the user was successful or did ..

  Write a program that simulate n rolls of six-sided die

Write a program that simulate n rolls of six-sided die and displays the frequency of occurrence of each side and What is the most likely method signature of the "parseInt() - TNE60003

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