WC.exe (Java implementation)

  A, GitHub project address: https: //github.com/nullcjm/mypage

  Second, the project requirements:

wc.exe is a common tool, you can count the number of characters of text files, words, and lines. The project asked to write a command line program, to mimic the function of the existing wc.exe, and be expanded, given the number of characters in a programming language source files, words, and lines.

Implement a statistical program, the number of characters it can correct statistics program file, the number of words, lines, and also has other extended functions, and can handle multiple files quickly.
Specific functional requirements:
mode handles user needs to:

wc.exe [parameter] [file_name]

The basic list of features:

wc.exe -c file.c // returns the number of characters in the file file.c

The number of wc.exe -w file.c // Returns the file of the word file.c  

wc.exe -l file.c // returns the number of rows of file file.c

Extensions:
    -s recursive processing files that meet the conditions of the directory.
    -a return more complex data (line / space lines / comment lines).

Blank line: Bank format all control characters or spaces, if included code, no more than a displayable character, such as "{."

Line: Bank codes comprises more than one character.

Comment lines: lines of code instead of the Bank, and the Bank includes comments. An interesting example is that some programmers will add a comment behind a single character:

    } // NOTE
In this case, the line belongs to a comment line.

[file_name]: file or directory name, you can handle general wildcard.

Advanced Features:

 -x parameter. This parameter is used alone. If you have the command line parameters, the program will display a graphical interface, the user can select a single file through the interface, the program will display the file number of characters, lines, etc. All statistics.

Demand For example:
  wc.exe -s -a * .c

The number of lines of code returns the current directory and all subdirectories * .c files, the number of blank lines, comments, number of rows.

  Three, PSP form:

PSP2.1

Personal Software Process Stages

Estimated time consuming (minutes)

The actual time-consuming (minutes)

Planning

plan

 30

 30

· Estimate

• Estimate how much time this task requires

 30

 30

Development

Develop

 660

 780

· Analysis

· Needs analysis (including learning new technologies)

 240

 300

· Design Spec

Generate design documents

 30

 30

· Design Review

· Design Review (and his colleagues reviewed the design documents)

 30

 30

· Coding Standard

· Code specifications (development of appropriate norms for the current development)

 30

 30

· Design

· Specific design

 30

 30

· Coding

· Specific coding

 180

240 

· Code Review

· Code Review

 60

 60

· Test

· Test (self-test, modify the code, submit modifications)

 60

 60

Reporting

report

 120

 140

· Test Report

· testing report

 60

 80

· Size Measurement

· Computing workload

 30

 30

· Postmortem & Process Improvement Plan

· Hindsight, and propose process improvement plan

 30

 30

total

 810

 950




  Fourth, the problem-solving ideas: After reading about the project requirements soon had a problem-solving ideas, statistics on the number of lines, words, etc. in the production of a text editor there related, it took a long time to re-main Java learning-related knowledge (such as: regular expressions, etc.), with reference to the problem-solving ideas of others, we found that the idea is much the same, it took some time after finally achieved related functions.

                                                                                                    
  Fifth, function realization

    1.   WC main class

      import java.io.BufferedReader;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.util.Scanner;

      public class WC {

      static void main public (String [] args) throws IOException {
      the while (to true) {
      System.out.println ( "Instructions:");
      System.out.println ( "************ ************************** ");
      System.out.println (" returns the file number wc.exe -c file.c characters: ");
      System.out.println (" wc.exe -w file returns file.c number of words ");
      System.out.println (" wc.exe the -l file file.c return the number of rows ");
      System.out.println ( "wc.exe -a return file file.c blank lines, lines of code, comment line");
      System.out.println ( "wc.exe -x enable GUI");
      System.out .println ( "**************************************");
      System.out.println ( "input command:");

      Scanner Scanner new new iNPUT = (the System.in); // input command from the keyboard and performs
      String commend = input.nextLine ();
      switch (commend) {
      case "-c":
      Charcount ch = new Charcount();
      break;
      case "-w":
      Wordcount wc = new Wordcount();
      break;
      case "-l":
      Linecount line = new Linecount();
      break;
      case "-a":
      Complex cp = new Complex();
      break;
      case "-x":
      WCJFrame wf = new WCJFrame();
      break;
      default:
      System.out.println("指令错误,请重新输入:");
      break;
      }

      }
      }
      }

       

    2. -c command to achieve

      charCount class {public
      String REGEX = "\\ S";
      charCount () throws IOException {
      System.out.println ( "input path:");
      Scanner Scanner new new INPUT = (the System.in);
      String path input.nextLine = ( );
      the BufferedReader new new FIS = the BufferedReader (new new the FileReader (path));
      int charCount = 0;
      String W;
      the Pattern of Pattern.compile P = (REGEX); // match the appropriate character
      while ((w = fis.readLine () ) ! = null) {
      Matcher m = p.matcher (W);
      the while (m.find () time) // find the number of characters corresponding to characters + 1'd

      charCount ++;
      }
      System.out.println ( "number of characters:" + charCount);
      fis.close ();

      }
      }

       

    3. -w command to achieve

      WORDCOUNT class {public
      String REGEX = "[A-zA-the Z] + \\ B"; // determination condition is a regular expression word
      WORDCOUNT () throws IOException {
      System.out.println ( "input path:");
      INPUT = new new Scanner Scanner (the System.in);
      String path input.nextLine = ();
      the BufferedReader new new FIS = the BufferedReader (new new the FileReader (path));
      int WordCount = 0;
      String W;
      the Pattern of Pattern.compile P = (REGEX) ;
      the while (! (W = fis.readLine ()) = null) {
      Matcher m = p.matcher (W);
      number while (m.find ()) // when finding matching content word + 1'd
      WordCount + +;
      }

      System.out.println ( "number of words:" + WordCount);
      fis.close ();
      }
      }

       

    4. -l command to achieve

      LineCount {class public
      LineCount () throws IOException {
      System.out.println ( "input path:");
      Scanner Scanner new new INPUT = (the System.in);
      String path input.nextLine = ();
      the BufferedReader new new FIS = the BufferedReader (new new the FileReader (path));
      int LineCount = 0;
      ! the while (fis.readLine () = null) {// when the current line is not empty, the number of rows + 1
      LineCount ++;
      }
      System.out.println ( "rows:" LineCount +);
      fis.close ();

      }
      }

       

    5. -a command to achieve

      Complex class {public

      Complex () throws IOException {
      System.out.println ( "input path:");
      Scanner Scanner A new new = (the System.in);
      String path a.nextLine = ();
      the BufferedReader new new FIS = the BufferedReader (new new the FileReader (path));
      int SPACECOUNT = 0;
      int notecount = 0;
      int codecount = 0;
      Boolean = State to false;
      String C;
      ! the while ((C = fis.readLine ()) = null) {
      IF (c.contains ( "/ *")) {// begin multi-line comment tag
      notecount ++;
      State = to true;
      }
      the else IF (State) {
      notecount ++;
      IF (c.contains ( "* /")) {// end tag multi-line comments
      = to false State;}
      }
      the else IF (c.contains ( "//")) {// single line comment marker
      notecount ++;
      }
      else if (. c.trim () length ()> 1) {// is determined that the line condition
      codecount ++;
      }
      the else {SPACECOUNT ++;}
      }

      fis.close ();
      System.out.println ( "blank line:" + SPACECOUNT);
      System.out.println ( "comment line:" + notecount);
      System.out.println ( "line of code:" + codecount);
      }
      }

       

  Sixth, functional testing

  1. test document :

  Empty file (1.txt)
  only file (2.txt) a character
  is only a word document (3.txt)
  only one line of the file (4.txt)
  a typical source files (5.txt)

  2.-c command regression testing

  

  3.-w, -a, -x test instruction

  

  4.-x Test instruction

  

  

  Seven tips Review

  The first detailed plan to complete a project, all parties feel harvested a great deal. Not only review previously learned knowledge, but also learned to use newly learned knowledge. But the timing is still a big problem, this could be improved.

Guess you like

Origin www.cnblogs.com/nullcjm/p/11587364.html