Development Cycle Third Iteration


Development Cycle Second Iteration

With the RobotRat application class structure in place and tested, it is time to add another piece of functionality to the program.

Plan (Second Iteration)

A good piece of functionality to add to the RobotRat class at this time would be the text menu that displays the list of available robot rat control options. Refer to the project specification to see a suggested menu example. Table 3-7 lists the features that will be added to RobotRat during this iteration.

Table 3-7: Second Iteration Design Considerations

Check-Off

Design Consideration

Design Decision

 

Display control menu to the console

Create a RobotRat method named printMenu() that prints the menu tothe console. Test the printMenu() method by calling it from the constructor. The printMenu() method will return void and take no arguments. It will use the System.out.println() method to write the menu text to the console.

This looks like enough work to do for one iteration. You can now move to the code phase.

Code (Second Iteration)

Edit the image from book RobotRat.java source file to add a method named printMenu(). Example 3.2 shows the image from book RobotRat.java file with the printMenu() method added.

Example 3.2: RobotRat.java (2nd Iteration)

image from book
 1    public class RobotRat { 2 3      public RobotRat(){ 4        printMenu(); 5       } 6 7       public void printMenu(){ 8         System.out.println("\n\n"); 9         System.out.println("Robot Rat Control Menu"); 10        System.out.println("\n"); 11        System.out.println("   1. Pen Up"); 12        System.out.println("   2. Pen Down"); 13        System.out.println("   3. Turn Right"); 14        System.out.println("   4. Turn Left"); 15        System.out.println("   5. Move Forward"); 16        System.out.println("   6. Print Floor"); 17        System.out.println("   7. Exit"); 18        System.out.println("\n\n\n"); 19      } 20 21 22       public static void main(String[] args){ 23        RobotRat rr = new RobotRat(); 24       } 25   }
image from book

The printMenu() method begins on line 7. Notice how it’s using the System.out.println() method to write menu text to the console. The “\n” is the escape sequence for the newline character. Several of these are used to add line spacing as an aid to menu readability.

Notice also that the code in the constructor has changed. The line printing the “RobotRat Lives!” message was removed and replaced by a call to the printMenu() method on line 4.

When you’ve finished making the edits to image from book RobotRat.java you are ready to compile and test.

Test (Second Iteration)

Figure 3-7 shows the results of testing RobotRat at this stage of development. The menu seems to print well enough.

image from book
Figure 3-7: Compiling & Testing RobotRat.class - Second Iteration

Integrate/Test (Second Iteration)

Again, there is not much to integrate or regression test. If you are happy with the way the menu looks on the console you can move on to the third iteration of the development cycle.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net