WC individual projects (JAVA realize)

A, Github address: https: //github.com/l67t/wc

Two, PSP form

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 30 40
· Estimate • Estimate how much time this task requires 30 40
Development Develop 1155 1220
· Analysis · demand analysis  50 60
· Design Spec Generate design documents 30 40
· Design Review · Design Review  20 20
· Coding Standard · Code Specification 15 30
· Design · Specific design 80 60
· Coding · Specific coding 750 800
· Code Review · Code Review 30 30
· Test · Test (self-test, modify the code, submit modifications) 180 180
Reporting report 110 130
· Test Report · testing report 60 60
· Size Measurement · Computing workload 20 30
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 30 40
total   1295 1390

Third, the problem-solving ideas

Because before JAVA class has similar functionality with this project, so I chose to use JAVA to achieve.

Functional Analysis

(1) counts characters (achieved by calculating the length of a text document content)

(2) the number of words statistics (through statistics the number of spaces between words)

(3) statistics rows ( '\ n' is achieved by counting the number)

(4) the number of blank lines to statistics, the number of comment lines, number of lines of code (use regular expressions to achieve)

(5) supports wildcards (unrealized)

(6) a graphical interface (not implemented)

(7) Under Process directories recursively eligible files (not implemented)

In the design of the graphical interface I had some problems, first frame, I need to build a certain window to resize the window to display the contents, I do have a review in accordance with the method to set the window size setSize (), and then display the form setVisible (), but that does not work, then that call methods and functions, but because of the previous code, I first determine the "-c, -l, -w" these instructions enable other class methods, and then enter the path of by judging the input command is completed, leading to calls and do not know how to use getPath () by choosing the file path to get input when creating a graphical interface, you need to recompile the front most of the code can be modified, ultimately, to abandon graphical interface, Although the statistical methods used in the class before all go into the graphical interface, but such codes are too bloated, just repeat the previous code, no use to other classes, become completely separated from the completion of the previous function class, but the most important thing is lack of personal coding ability, did not do pre-planning function, post-modification fatigue, As written by the same teacher in the program requirements, Practice Makes Perfect.  There are no shortcuts, that is to practice, practice and more practice! After this simple personal project, I found my programming ability is really very low, so my future should strive to practice my programming skills, more training and more thinking, raise the level.

Fourth, the design and implementation process

There are six project categories:

1.WC (main class)

2.CodeCount (realized character statistics)

3.WordCount (realization word count)

4.LineCount (the number of rows to achieve statistical)

5.Extra (extended functionality, the number of blank lines, comments, number of rows, the number of lines of code statistics)

 Fifth, test run

Test file

 

 

(1) character counts

 

 

(2) the word count 

 

 

 

(3) the number of lines statistics

 

 

 

Statistics (4) blank line, a comment line number, the number of lines of code

 

 

Import java.util.Scanner; 

public  class the WC { 

    public  static  void main (String [] args) { 
        System.out.println ( "************************************************************ ************************************************************ " ); 
        System.out.println ( " instructions: " ); 
        System.out.println ( " wc.exe -c // returns the number of characters in the file " ); 
        System.out.println ( " wc.exe -w // returns the number of words in the file " ); 
        System.out.println ( " wc.exe the -l // returns the file the number of rows " ); 
        System.out.println ( " wc.exe -a // returns the number of empty lines in the file, the number of lines of code number of comment lines " ); 
        System.out.println ("*********************************************" );     
        Scanner Scan = new new Scanner (the System.in); 
        String Order = null ;
         the while ((scan.nextLine Order = ()) = "!" ) {
         Switch (Order) {
         Case "wc.exe -C": the System.out. println ( "Please enter a file path:" );
                          new new Codecount (); BREAK ;
         Case "wc.exe -w": System.out.println ( "Please enter a file path:" );
                          new new wordcount (); BREAK ;
         Case"wc.exe -l": System.out.println ( "Please enter a file path:" );
                          new new LineCount (); BREAK ;
         Case "wc.exe -a": System.out.println ( "Please enter a file path : " );
                           new new Extra (); BREAK ;                
         default : System.out.println (" error command input, please re-enter the command: " ); 
        } 
        
    } 
        scan.close (); 
        
}}
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;

public class Codecount {
    Scanner c=new Scanner(System.in);{
    String Pathname=null;
    while((Pathname=c.nextLine())!="") {
    File file=new File(Pathname);{
    try {
        FileReader fr=new FileReader(file);
        char temp[]=new char[4096];
        int a=fr.read (TEMP);
         IF (A == -. 1) A = A +. 1 ; 
        System.out.println ( "the number of characters of the file is" + A); 
        fr.close (); 
        } the catch (Exception E) { 
            System.out.println ( "path is incorrect, please re-enter the path:" ); 
        } 
    
                                 } 
    
    } 

}}
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;

public class Wordcount {
    Scanner w=new Scanner(System.in);
    String Pathname=null;{
    while((Pathname=w.nextLine())!="") {
    File file=new File(Pathname);{
    try {
        FileReader fr=new FileReader(file);
        char temp[]=new char[4096];
        int b=0;
        int A = fr.read (TEMP);
         for ( int I = 0; I <A; I ++ ) {
             IF (TEMP [I] == '' ) 
                B ++ ; 
            } 
        IF (A == -. 1) B = -1 ; 
        System.out.println ( "number of words in the text as" + (B +. 1 )); 
        fr.close (); 
    } the catch (Exception E) { 
        of System.out.print ( "file path for the error, re-enter: " ); 
    } 
}}}}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;

public class Extra {
    Scanner e=new Scanner(System.in);
    String Pathname=null;
    String kregex="(\\s)*[{]?";{
    while((Pathname=e.nextLine())!="") {
        File file=new File(Pathname);{
        try {
            String s=null;
            int a=0,c=0,b=0;
            FileReader fr=new FileReader(file);
            BufferedReader bufr=new BufferedReader(fr);
            while((s=bufr.readLine())!=null) {
                if(s.contains("//"))
                    a++;
                else if(s.matches(kregex))
                    b++;
                else c++;
                }                                                               
            System.out.println("文本的空行数为:"+a);
            System.out.println ( "number of comment lines of text is:" + B); 
            System.out.println ( "number of lines of text is:" + C); 
            fr.close (); 
            bufr.close (); 
            } 
        the catch (Exception E) { 
            e.printStackTrace (); 
            System.out.println ( "file path input errors, please re-enter:" ); 
                           } 
                                      } 
                                        } 
                        
                    } 
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;
public class Linecount {
    Scanner l=new Scanner(System.in);
    String Pathname=null;{
    while((Pathname=l.nextLine())!="") {
    File file=new File(Pathname);{
        try {
        FileReader fr=new FileReader(file);
        BufferedReader bufr=new BufferedReader(fr);
        int I = 0 ;
         the while ((bufr.readLine ()) =! null ) { 
            I ++ ; 
        } 
        System.out.println ( "number of lines of text as" + I); 
        fr.close (); 
        bufr.close ( ); 
        } the catch (Exception E) { 
            System.out.println ( "file path input errors, please re-enter:" ); 
        } 
    } 
}}}

 

Guess you like

Origin www.cnblogs.com/yejianting/p/11588653.html