title: how to randomly populate a 2D array with random single digit ints
body: <p>I want to create a map (AWorld) that is basically a 25x25 grid of cells bordered with | and blank inside other than the the random occurrences of random numbers between 0-9 that according to their value (eg.g 8) will offer a object of type ABug energy when the bug moved over it. </p>
  
  <p>e.g. 
  <a href="http://i.stack.imgur.com/tVFkT.png" rel="nofollow">the world minus the horizontal lines.</a></p>
  
  <p>now I seem to be having some outofBoundsexception with my array and i cant for the life of me figure out what im doing wrong (im very new to java and object orientation in generall having only bearly got the hang of c++ last term). </p>
  
  <p>my code is as follows </p>
  
  <p>the ABug class:</p>
  
  <pre><code>public class ABug 
  
  {
  
  
  public static void main(){
  
  }
  
      private String species = new String(); //instance variables (defines data of object)
      private String name = new String();
      private String description = new String();
      private char symbol;
      private int hPossistion, vPossistion, energy, iD;
  
      public ABug(){
  
      }
  
      public ABug (String s, String n, String d, int h, int v, int e, int i){
          this.species = s;
          this.name = n;
          this.description = d;
          this.symbol = s.charAt(0);
          this.hPossistion = h;
          this.vPossistion = v;
          this.energy = e;
          this.iD = i;
      }
  
  
  
  
      //setters
      public void setSpecies(String s){
          this.species = s;
      }
  
      public void setName(String n){
          this.name = n;
      }
  
      public void setSymbol(char symbol){
          this.symbol = symbol;
      }
  
      public void setHPossistion(int x){
          this.hPossistion = x;
      }
  
      public void setVPossistion(int y){
          this.vPossistion = y;
      }
  
      public void setEnergy(int energy){
          this.energy = energy;
      }
  
      public void setID(int i){
          this.iD = i;
      }
  
      public void setDescription(String d){
          this.description = d;
      }
  
      //getters
      public String getSpecies(){
          return this.species;
      }
  
      public String getName(){
          return this.name;
      }
  
      public char getSymbol(){
          return this.symbol;
      }
  
      public int getHPossistion(){
          return this.hPossistion;
      }
  
      public int getVPossistion(){
          return this.vPossistion;
      }
  
      public int  getEnergy(){
          return this.energy;
      }
  
      public int getID(){
          return this.iD;
      }
  
      public String getDescription(){
          return this.description;
      }
  
      public String toString(){
          String BugData;
          BugData = name + " " + symbol + "\n" + species + "\n" + description;
          return BugData;
      }
  
  
  
  
  
  
  }
  </code></pre>
  
  <p>the AWorld Class:</p>
  
  <pre><code>package finalversion;
  
  import java.util.Arrays;
  import java.util.Random;
  
  public class AWorld {
  
  public static int RandFood(int min, int max){
      Random rand = new Random(); // Initializes the random function. 
  
      int RandNum = rand.nextInt((max - min) +1) + min; //generates a random number within the max and min ranges 
      return RandNum; //returns the random number 
  }
  
      public static void main(String[] args){
  
      ABug bug1 = new ABug();     
      int row = 25;
      int column = 25;
      char [ ][ ] map = new char[row][column];
      Random rand = new Random();
      int hPossistion = rand.nextInt();
      int vPossistion = rand.nextInt();
  
      for (int i=0; i&lt;column; i++)
      {
      map[hPossistion][vPossistion] = (char) RandFood(0,9); &gt; // this is where is is getting the error.
  
      }
      for (int i=0; i&lt;row; i++)
      {
  
          for (int x1=0; x1&lt;column; x1++)
          {
              map[i][x1] = ' ';
  
  
          }
  
      }
          map[bug1.getHPossistion()][bug1.getVPossistion()] = bug1.getSymbol(); // gets the bugs x and y possistion in the array (user defined) and puts it into the symbol variable 
  
  
      for (int i=0; i&lt;row; i++) //these next two for loops print the array to the screen 
      {
          System.out.print("|");
          for (int x1=0; x1&lt;column; x1++) 
          {
              map[i][x1] = ' ';
              System.out.print(map[i][x1]);
  
          }
          System.out.println("|");
      }
  
  
  
  
  
  
  }  
  
  }
  </code></pre>
  
  <p>main:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class UserInput {
  
  public static void main(String[] args)
  {
      Scanner Scan = new Scanner(System.in);
      AWorld World = new AWorld();
      ABug Abugs[];
      int top=0;
      System.out.println("please enter how many bugs you want to create?");
      int  num = new Integer( Scan.nextLine() );
      Abugs = new ABug[num];
  
      int x=0;
  
      ABug bug = new ABug(" ", " ", " ", 0, 0, 0, 0);
  
      ///////////////////////////////////////////////////////////////
  
      System.out.println("please enter a Species Name");
      String s = Scan.nextLine();
      bug.setSpecies(s);
  
  
      /////////////////////////////////////////////// 
  
      System.out.println("please enter a name for the bug");
      String n = Scan.nextLine();
      bug.setName(n);
  
      //////////////////////////////////////////////
  
  
      System.out.println("please enter a Symbol for the bug");
      char sy = Scan.nextLine().charAt(0);
      bug.setSymbol(sy);
  
      ///////////////////////////////////////////////////////////
  
      System.out.println("please enter a description for the bug");
      String d = Scan.nextLine();
      bug.setDescription(d);
  
      /////////////////////////////////////////////////////
  
      System.out.println("please enter the energy for the bug");
      int e = new Integer( Scan.nextLine() );
      bug.setEnergy(e);
  
      ///////////////////////////////////////////////////////
  
      System.out.println("please enter the horisontal position for the bug");
      int h = new Integer( Scan.nextLine() );
      bug.setHPossistion(h); 
  
      /////////////////////////////////////////////////////////////
  
      System.out.println("please enter the vertical position for the bug");
      int v = new Integer( Scan.nextLine() );
      bug.setVPossistion(v);
  
      ////////////////////////////////////////////////////////////////
  
      Abugs[x] = bug;
  
      System.out.println( Abugs[x].toString() );
  
  
      ////////////////////////////////////////////////////////
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i'v been stuck on this for 3 days and cant seem to get my head around it. </p>