Picture of Cover

         
Home
Textbook
Software
Robot Examples
Pick3
GraphOne
GraphMultiple
GraphThreads
Checkers
Robots Documentation
Demos of becker.xtras
Java Documentation
Downloads
Installation
Favorite Tools
Change Log
Instructors
 
Printer Friendly Page

Sample Code: GraphCity.java

package examples;
import becker.robots.*;

public class GraphCity extends City
{
   /** Create a special kind of city that includes "data" (piles of things)
       to creat a graph.  The piles are all on the same avenue on consecutive
       intersections.  The size of each pile is determined by a random number
       generator.
       @param numPiles the number of piles of things
       @param startAve the avenue to place them on
       @param startStr the first street to contain a pile
       @param maxDataInPile the maximum amount of data in any pile */
   public GraphCity(int numPiles, int startAve, int startStr, int maxDataInPile)
   {  super();
      for(int s=startStr; s<startStr + numPiles; s++)
      {  int size = (int)(Math.random() * maxDataInPile) + 1;
         this.makeThingPile(startAve, s, size);
      }
   }

   /** Make a pile of things.
       @param ave The avenue where the things should be placed
       @param str The street where the things should be placed
       @param num The number of things to put in the pile */
   private void makeThingPile(int ave, int str, int size)
   {  for(int d=0; d<size; d++)
      {  new Thing(this, ave, str);
      }
   }
}


Contact: bwbecker@learningwithrobots.com.