/**
 * Walks a student home (spoiler: she's drunk).
 * @author Ryan Closner
 * @version 11/5/2012
 **/

import java.util.*;

class Drunk
{
    // Instantiate location variables

    private static final int START = 5;
    private static final int HOME = 0;
    private static final int JAIL = 10;

    // Number of times to walk

    private static final int N = 5;

    // Drunk walk N times

    public static void main (String[] args)
    {
        int steps;
        String location;

        for (int i = 0; i < N; i++) {
            steps = drunkWalk(); 

            // If steps is negative, student is in jail. Otherwise she is at home.

            if (steps < 0) {
                steps = steps * -1; 
                location = "in JAIL";
            } else {
                location = "at HOME";
            }

            // Print walk details.

            System.out.println("Here we go again... time for a walk!");
            System.out.println("Took " + steps + " steps, and");
            System.out.println("Landed " + location);
            System.out.println();
        }
    }

    /**
     * Walks the student until she has reached home or jail
     * @return the number of steps taken (negative means she is in jail, positive means at
     * home).
     **/
    private static int drunkWalk ()
    {
        // Initial location set to start.

        int location = START; 

        // Initial location set to 0.

        int steps = 0;

        // Initialize number generator.

        Random generator = new Random();

        // 0.5 chance she walks towards home or jail.

        while (location != HOME && location != JAIL)
        {
            location += (generator.nextInt(2) == 0) ? -1 : 1;
            steps++;
        }

        // If she is at home, return positive. Otherwise return negative.

        return (location == HOME) ? steps : -steps;
    }

}

@@ -1,20 +1,36 @@
 /**%0A * 
-Walks
+Prints the results of
  a stude
@@ -31,16 +31,23 @@
  student
+'s walk
  home (s
@@ -155,16 +155,104 @@
 Drunk%0A%7B%0A
+    // Number of times to try drunk-walking home.%0A%0A    private static final int N = 5;%0A%0A
     // I
@@ -280,16 +280,17 @@
 ariables
+.
 %0A%0A    pr
@@ -407,77 +407,8 @@
 0;%0A%0A
-    // Number of times to walk%0A%0A    private static final int N = 5;%0A%0A
     
@@ -428,16 +428,17 @@
  N times
+.
 %0A%0A    pu
@@ -473,32 +473,66 @@
 g%5B%5D args)%0A    %7B%0A
+        // Instantiate variables%0A%0A
         int step
@@ -558,16 +558,90 @@
 ocation;
+%0A        float total = 0;%0A        float average;%0A%0A        // Walk N times.
 %0A%0A      
@@ -731,18 +731,19 @@
 f steps 
-is
+are
  negativ
@@ -1231,25 +1231,285 @@
 ntln();%0A
-        %7D
+%0A            // Add the number of steps to the total.%0A            %0A            total += steps;%0A        %7D%0A%0A        // Calculate the average.%0A%0A        average = total / N;%0A%0A        // Print the average.%0A%0A        System.out.println(%22Average # of steps equals %22 + average);
 %0A    %7D%0A%0A

Print average statistics