Armed with an understanding of the project requirements, problem domain, language features, and an implementation approach, you are ready to begin development. To complete the project, apply the development cycle iteratively, meaning apply each of the development cycle phases —plan, code, test, and integrate —to a small, selected piece of the overall problem. When you’ve finished that piece of the project, select another piece and repeat the process. The following sections step through the iterative application of the development cycle to the robot rat project.
A good way to start each iteration of the development cycle is to list those pieces of the programming problem you are going to solve this time around. The list should have two columns: one that lists each piece of the program design or feature under consideration and one that notes the design decision made regarding that feature. Again, the purpose of the list is to help you maintain a sense of forward momentum. You may find, after you make the list, that you need more study in a particular language feature before proceeding to the coding step. That’s normal. Even seasoned programmers occasionally need to brush-up on unfamiliar or forgotten language features or application programming interfaces (API). (i.e., the Java platform APIs or third-party APIs)
The list of the first pieces of the robot rat project that should be solved based on the previously discussed implementation approach is shown in table 3-6.
Check-Off | Design Consideration | Design Decision |
---|---|---|
Program structure | One class will contain all the functionality. | |
Creating the Java application class | The class name will be RobotRat. It will contain a “public static void main(String[] args){ }” method. | |
constructor method | Write a class constructor that will print a short message to the screen when a RobotRat object is created. |
This is good for now. Although it doesn’t look like much, creating the RobotRat application class and writing a constructor that prints a short text message to the console are huge steps. You can now take this list and move to the code phase.
Using your development environment create the RobotRat project. Create a Java source file named RobotRat.java and in it create the RobotRat class definition. To this class add the main() method and the RobotRat constructor method. When complete, your RobotRat.java source file should look similar to example 3.1.
Example 3.1: RobotRat.java (1st Iteration)
1 public class RobotRat { 2 3 public RobotRat(){ 4 System.out.println("RobotRat lives!"); 5 } 6 7 8 public static void main(String[] args){ 9 RobotRat rr = new RobotRat(); 10 } 11 }
After you have created the source file you can move to the test phase.
The test phase of the first iteration involves compiling the RobotRat.java file and running the RobotRat.class file. If the compilation results in errors you must return to the code phase, edit the file to make the necessary correction, and then attempt to compile and test again, repeating the cycle until your are successful. When you have successfully compiled and tested the first iteration of the RobotRat program you can move on to the next step of the development cycle. Figure 3-6 shows the results of running example 3.1.
Figure 3-6: Compiling & Testing RobotRat Class - First Iteration
There’s not a whole lot to integrate at this point so you are essentially done with the first development cycle iter-ation. Since this version of the robot rat project is contained in one class named RobotRat, any changes you make directly to the source file are immediately integrated. However, for larger projects, you will want to code and test a piece of functionality, usually at the class granularity, before adding the class to the larger project.
You are now ready to move to the second iteration of the development cycle.