Many beginners, when they first learn programming, just want to code! Code!!!!! Code!!
But do you know what programming is?
Know this: Coding ≠ programming
Today we will introduce a fast start programming routines, coding on the basis of routines is like god help!
As anyone who has studied Java syntax knows, although it may seem like so much, it can be summed up in two functions. One is to store data, the other is to manipulate data.
Variables, arrays, collections, file manipulation, JDBC, etc., are related to data storage, while select statements, loop statements, multithreading, reflection, etc., are related to data manipulation.
Today’s routine is to teach you, the requirements encountered by this way to classify, you can quickly get started, write a set of beautiful code!
The example of this routine is illustrated in my previous article “Java from Starter to Quit” JavaSE: Exercise – Single Dog Rental System (Array edition).
The requirements for this example are shown below:
Everybody, ready? Let’s go!!
The above requirements can also be divided into data storage and data manipulation.
Data storage: Single dog attributes
Data operations: view, add, delete, lend, return
But beyond that, the implementation of functionality should also include interface operations and common operations.
General operation: according to the specified format display date, random generation number
Interface operation: main interface, add interface, delete interface, view interface, etc
Once the analysis is complete, you can write the framework code as follows:
Public class SingleDogManager {String[] id = new String[100]; // serial number String[] nickname = new String[100]; // nickname int[] gender = new int[100]; Int [] state = new int[100]; Date[] Date = new Date[100]; // Loan Date: Date is the Date type (format: Public void add(){} public void add(){} public void delete(){} public void delete(){ Public void loan(){}// return public void repay(){} public void mainMenu(){} public void showUI() { } // Add interface public void addUI(){} // delete interface public void deleteUI(){} // Lend interface public void loanUI(){} // return interface public void RepayUI (){} public void init(){}// Generate a new number (not repeated)private String createID() {}// Format the display date private String toDate(Date d){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(d); }}Copy the code
The next thing is not to say more, to clarify the relationship between each method.
-
On the main menu interface, call the corresponding data operation method interface according to different choices.
-
The data manipulation method interface invokes the corresponding data manipulation method.
-
Data manipulation methods that call generic methods as needed to change or display data stored in arrays as needed.
According to the logical order of each method corresponding functional code written on the end of OK!
I’m not going to copy the code. Need Java learning material video can add group: 1080355292
To summarize the routine:
Step 1: Analyze requirements into four parts: data storage, data manipulation, interface manipulation, and general operation.
Step 2: clarify the method call relationship between each module.
Step 3: Code each method in logical order.
Beginners, do you understand? The next step is to practice and make this routine a habit!!
Always believe that you can make it!
(Pep talk, come on)