Pair programming work (metro line problems)
A task
Assist in the realization of a subway travel route planning command-line program.
1. Requirements:
Requirement 1:
implement a support program to calculate and display the subway line transfer (for C ++ / C #, compiled binary file name must be a subway.exe; for Java project, Main method where the file name must be a subway.java). After that, the user can start the program from the command line. When the program starts, it reads the command line parameters corresponding to different commands. For information subway map, we agreed to adopt it as a parameter -map flag. It is necessary to obtain a corresponding custom file metro (designated subway.txt) -map parameters by reading the program starts, to obtain information subway map.
Requirement 2:
users want to query specifies subway line through the site. In the application needs to support a new command line parameter -a
that specifies the user wishes to query subway lines. Thus, at a given subway line, it needs to be able to start the program from the start site of the line, all sites sequentially output through the subway lines until the terminal. The output file using the -o
command-line arguments.
Requirement 3:
users want to take the subway, he hopes to pass the minimum number of stations to reach the destination from the starting point, so that you can add to two subway stations -b parameter name on the command line are used as starting with the purpose, such as the user wants to know Honghu the shortest route between the inside Fuxing Road, what, he can use the following command to let the program will result in a write routine.txt.
2.PSP
PSP 2.1 | Personal Software Process Stages | Time |
---|---|---|
Planning | plan | |
· Estimate | • Estimate how much time this task requires | 2weeks |
Development | Develop | |
· Analysis | · Needs analysis (including learning new technologies) | 2days |
· Design Spec | Generate design documents | 1day |
· Design Review | · Design Review (and his colleagues reviewed the design documents) | 1day |
· Coding Standard | · Code specifications (development of appropriate norms for the current development) | 1day |
· Design | · Specific design | 2days |
· Coding | · Specific coding | 2days |
· Code Review | · Code Review | 1day |
· Test | · Test (self-test, modify the code, submit modifications) | 1day |
Reporting | report | |
· Test Report | · testing report | 0.5day |
· Size Measurement | · Computing workload | 0.5day |
· Postmortem & Process Improvement Plan | · Hindsight, and propose process improvement plan | 1day |
total | 15days |
Second, the calculation of the design and implementation of the interface module
Third, the calculation module design and implementation of the interface:
1. Description source data structure:
Line represents a line, the line sequence is the date line, such as a first row represents the 1st line, separated by commas station, sequential
2. Entity class properties
An entity class defines Station
Information contained in the following
private String name; // the name of the subway station, comprising assumed uniqueness
public Station prev; // site in front of a station line lineNo above
public Station next; // site after lineNo line above a station
// site to a certain target station (key) through which all stations set (value), before and after the sequence remains
private Map <station, LinkedHashSet <station >> orderSetMap = new HashMap <station, LinkedHashSet <station >> ();
3. The key class (Subway) algorithm to achieve and thought:
// Calculation using Dijkstra's shortest path algorithm s2 from s1 station to station through the shortest path
public void calculate (Station s1, Station s2);
// get the shortest distance to the station parameters of each station, a station spaced a distance of 1, and so on
private Station getShortestPath (Station station);
// Get all stations connected directly to station parameters, including intersecting lines above station
private List <Station> getAllLinkedStations (Station station);
// The output path output content
public static void output (String [] content, String ouputPath);
4. Display the project directory
IV. Test results and run
V. Summary:
Through this pair after the program is completed, found a lot of problems, I feel their own lack of ability, or is there have been difficulties in programming, then ask the students in question programming process, the teammates patiently explained to me, learned some practical knowledge of the operation, the training program, to review the two shortest path algorithm, Dijkstra's algorithm is used to solve the shortest path problem codes specific implementation, the map and the problems of storage, input and output, in short, help teammates or great, thanks to my teammates let me learn a lot of knowledge, or by a person I was not able to accomplish this job.
Six, Github address: https: //github.com/zxy960828/subway.git