Github Address :https://github.com/ztz1998/wc/tree/master

Project related requirements

Implement a statistical program , It can correctly count the number of characters in the program file 、 Number of words 、 Row number , And other extensions , And can quickly process multiple files .
Specific functional requirements :

List of basic functions :

wc.exe -c   file.c     // Return file file.c The number of characters ( Realization )

wc.exe -w  file.c    // Return file file.c The number of words used ( Realization )

wc.exe -l    file.c      // Return file file.c The number of rows ( Realization )

Extend the functionality :
wc.exe   -s   Recursively process the qualified files in the directory .( Unrealized )
wc.exe   -a   Return more complex data ( Lines of code / Blank line / Comment row ).( Unrealized )

PSP2.1 form

PSP2.1

Personal Software Process Stages

Estimated time ( minute )

The actual time consuming ( minute )

Planning

plan

 30  40

· Estimate

· Estimate how long this task will take

 30  40

Development

Development

 300  500

· Analysis

· Demand analysis ( Including learning new technology )

 60  100

· Design Spec

· Generate design documents

 20  0

· Design Review

· Design review ( Review design documents with colleagues )

30  60

· Coding Standard

· Code specification ( Develop appropriate specifications for current development )

 10  20

· Design

· Concrete design

 30  40

· Coding

· Specific code

 30 50 

· Code Review

· Code review

 0  0

· Test

· test ( Self test , Modify the code , Commit changes )

 30  30

Reporting

The report

 120  150

· Test Report

· Test report

10  20

· Size Measurement

· Calculate the workload

 20 20

· Postmortem & Process Improvement Plan

· Post event summary , And propose process improvement plan

 10  10

total

   730  1080

Their thinking

When I was a sophomore java When , The first step of the last job is to read the file , Also searched the Internet WordCounter Code , A combination of the two , The idea basically came out . Write the method to realize the function with the development language , Start writing code by looking up information on the Internet , Modify the code .

Design

The code is divided into two , One is the menu ( Main code , Start the program ), One is computation ( Logic function code ), Control functions through corresponding commands , The final output .

Variable :chars, words, lines.    The representation of basic functions .

Method :calculate                                How to realize the basic functions .

switch(arr[0])                    Classify functions and print out results .

Code

menu ( Main code , Start the program )

package my10;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
while (true){
System.out.println("$$$$$$$$$$$$$$$$$$$");
System.out.println("1: Number of characters 、 The number of words 、 Row number ");
System.out.println(" Enter the command :");
Scanner input=new Scanner(System.in);
String m=input.nextLine();
String arr[]=m.split("\\s");

try{
switch(arr[0]){
case"1":Counter.counter(); break;
}
}
catch (FileNotFoundException e) {
System.out.println("\n No files found ");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}

operation ( Logic function code )

package my10;

import java.io.*;
import java.util.Scanner;

public class Counter {
public static void counter( ) throws Exception {
Scanner input = new Scanner(System.in);
System.out.println(" Input path :");
String path = input.next();
File file = new File(path);
FileReader reader = new FileReader(file);

int countChar = 0;
int countword = 0;
int countline = 0;
InputStreamReader isr = new InputStreamReader(new FileInputStream(path));
BufferedReader br = new BufferedReader(isr);
while(br.read()!=-1)
{
String s = br.readLine();
countChar += s.length();
countword += s.split(" ").length;
countline++;
}
System.out.println(" Number of characters "+countChar);
System.out.println(" The number of words "+countword );
System.out.println(" Row number "+countline);
}
}

Running results

Difficulties encountered and solutions

1. Yes java Not very familiar with , We need to find information , And the final function is only the basic function .

2. At first switch(arr[0]), There is an error

Cannot switch on a value of type String for source level below 1.7.
Only convertible int values or enum constants are permitted

Only after Baidu did I know that 1.7 The above supports String, And I am 1.6

3. When the code is finished, it appears at runtime Could not find the main class, I don't know why , After Baidu also did not solve , In the end, the compiler was changed to be successful

summary

The first assignment at the beginning of school , It's not hard , But it's still hard , And we have to look it up on the Internet , Ask your classmates for help , Exposed to java I'm not familiar with , I hope I can learn more slowly , progress .

It's also the first time I've blogged .

java Realization wc.exe More articles about

  1. The small white のjava Realization wc.exe function

    GitHub Address Project completion List of basic functions ( The implemented ) wc.exe -c file.c     // Return file file.c The number of characters wc.exe -w file.c    // Return file file. ...

  2. Soft work No.1.Java Realization WC.exe

    website :https://github.com/a249970271/WC WC Project requirement wc.exe It's a common tool , It counts the number of characters in a text file . Number of words and lines . This project requires writing a command line program , Imitate the past w ...

  3. JAVA Realization WC.exe function

    Project requirement Implement a statistical program , It can correctly count the number of characters in the program file . Number of words . Row number , And other extensions , And can quickly process multiple files . Specific functional requirements : The program's mode of dealing with user needs is : wc.exe [paramet ...

  4. Java Realization WC.exe

    Github:https://github.com/YJOED/Code/tree/master/WC/src One . subject : Implement a statistical program , It can correctly count the number of characters in the program file . Number of words . Row number , And there are other ...

  5. Software Engineering :Java Realization WC.exe Basic function

    Project related requirements GitHub Address :https://github.com/3216004716/WC Implement a statistical program , It can correctly count the number of characters in the program file . Number of words . Row number , And other extensions , And be able to get in place quickly ...

  6. Soft work 1—java Realization wc.exe

    github Project address https://github.com/liyizhu/wc.exe WC Project requirement List of basic functions : wc.exe -c file.c     // Return file file.c The number of characters ...

  7. Software engineering practice 1 —— java And wc.exe

    SoftwareEngineering-wc github Project address :https://github.com/CuiLam/SoftwareEngineering-wc   Project related requirements Implement a statistical program ...

  8. Soft work 1:wc.exe Project development (java)

    Github Address :https://github.com/Zzhaomin/learngit Project related requirements : wc.exe It's a common tool , It counts the number of characters in a text file . Number of words and lines . This project requires writing a ...

  9. WC.exe(Java Realization )

    One .GitHub Project address :https://github.com/nullcjm/mypage Two . Project related requirements : wc.exe It's a common tool , It counts the number of characters in a text file . Number of words and lines . This project requires writing ...

Random recommendation

  1. Java Basic writing document —— Use Formatter Object load buffer (UsingAFormatter)

    Console program , Use Formatter Object is ready to write data to the file . Use Formatter Object's format() Method , Format data values into view buffers charBuf in . import static java.n ...

  2. IP Address , Subnet mask partition ( turn )

    IP Address partition tutorial IP And subnet mask we all know ,IP It's made up of four numbers , Here it is , So let's see 3 Class is commonly used IP A class IP paragraph 0.0.0.0 To 127.255.255.255 B class IP paragraph 128.0.0.0 To ...

  3. These niche apps make you more efficient N times !( necessary , Collection )

    Most of us , After I bought the computer , More and more software , Computers are getting stuck , The efficiency of work is also getting lower and lower . At the same time, it may be in an infinite vicious circle of software installation and unloading for a long time . Improving work efficiency is one of the advantages of computer office , The installed software can ...

  4. Start android Blog sharing

    Now start blogging , Share android Experience in development .

  5. c# Send email sample

    1. adopt gmail E-mail try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(& ...

  6. To configure Tomcat Medium Context Chinese problems in elements

    Release a name called helloapp Of web application ,helloapp be located D:\ I \helloapp. The way to publish is through configuration <CATALINA_HOME>/conf/Catalina/localhost ...

  7. use js To realize the skin changing function of the page ( belt cookie memory )

    use js To realize the skin changing function of the page js The realization of skin changing function is mainly through the use of js control CSS To achieve . The general implementation principle is as follows , 1. First define a basic page style style.css To make sure div The width and height of , Make the whole page D ...

  8. RobotFramework + Appium Mobile automation enables

    This time our mobile automation implementation route is roughly like this :  Python Language foundation   —> Robot Framework The test framework   —> Android SDK and Genymotion Simulator   —>  ...

  9. Windows PowerShell Introduction (4)- Count と Operator

    Windows PowerShellにおける Count と Operator の Usage method について learn びます. This time は Representative な Operator として. Arithmetic operators . Substitution operator . On rational operators . Comparison operators . Fan Yan operator . Permutation operators .ビット Operator . type ...

  10. Personal projects : Realization wc.exe(Java)

    This project Github Address :https://github.com/NNewBoy/wc Project related requirements Basic function :( The implemented ) -c Count the number of characters in the file -w Count the number of document words -l Count file lines Extend the functionality :( has ...