title: Printing/Updating Objects within a 4x4 Grid Using OOP
body: <p>Bear with me, the language isn't great and I'm extremely new to programming.</p>
  <p>I am meant to create a game in Java using Eclipse that uses OOP to create a 4x4 grid.</p>
  <p>I will be randomly placing objects in the coordinates of the grid using Random Num Gen and printing so the user can see what is in each cell through each turn. The grid will update as the objects are assigned new random positions each turn. The end product should look like this:
  <a href="https://i.stack.imgur.com/QgP4J.png" rel="nofollow noreferrer">Printed Grid</a></p>
  <h2>class Grid</h2>
  <pre><code>package grid;
  
  import java.util.ArrayList;
  
  
  public class Grid {
  
  //variables &amp; constructors//
  private ArrayList &lt;Row&gt; theRows = new ArrayList &lt;Row&gt; ();
  private final int NUMBER_OF_ROWS = 4;
  
  public Grid() {
      for(int loop =1; loop &lt;= this.NUMBER_OF_ROWS; loop++) {
          this.theRows.add(new Row(loop));
      }//end for loop
  }//end Grid constructor
  
  
  
  //use to find specific spot, check for enemies,etc
  public void printSquare(int row, int square) {
      
      
  }
          
  
  //Find out if Ogre is on Square
  public boolean isOgreOn (int row, int square) {
      
      for(Row tempRow : this.theRows) {
          if(tempRow.getNumber() == row) {
              //found correct row
              for(Square tempSquare : tempRow.getTheSquares()) {
                  if(tempSquare.getNumber() == square){       
                      //found the correct square
                      if(tempSquare.getTheOgre() == null) {
                          //The ogre is not here
                          return false;
                      }
                  }
              }
          }
      }
  return true;
  }// end isOgreOn method
  
  //Find out how many enemies on Square
  public int howManyOgreEnemiesOn(int row, int square) {
      for(Row tempRow : this.theRows) {
          if(tempRow.getNumber() == row) {
              //found correct row
              for(Square tempSquare : tempRow.getTheSquares()) {
                  if(tempSquare.getNumber() == square) {
                      //found correct square
                      return tempSquare.getTheEnemies().size();
                  }
              }
          }
      }
  return 0;
  
  
  }//end howManyOgreEnemiesOn
  
  }//End Grid Class
  </code></pre>
  <h2>class Row</h2>
  <pre><code>   package grid;
  
      import java.util.ArrayList;
  
      public class Row {
      
      //variables getter &amp; setters &amp; constructor//
  
      private int number;
      private final int ROW_SIZE = 4;
      private ArrayList &lt;Square&gt; theSquares = new ArrayList &lt;Square&gt; ();
      
      public int getNumber() {
          return number;
      }
  
      public void setNumber(int number) {
          this.number = number;
      }
  
  
      public ArrayList&lt;Square&gt; getTheSquares() {
          return theSquares;
      }
  
      public void setTheSquares(ArrayList&lt;Square&gt; theSquares) {
          this.theSquares = theSquares;
      }
  
      public Row(int number) {
          for(int loop = 1; loop &lt;= this.ROW_SIZE; loop++) {
              this.theSquares.add(new Square(loop));
          }//end for loop
      }//end Row constructor
      
      }//end Row class
  </code></pre>
  <h2>class Square</h2>
  <pre><code>import java.util.ArrayList;
  
  public class Square {
  
      //variables getter &amp; setters &amp; constructor//
      int number;
      Ogre theOgre;
      ArrayList&lt;OgreEnemy&gt; theEnemies = new ArrayList&lt;OgreEnemy&gt;();
  
  
      public Square(int number) {
          setNumber(number);
      }
  
      public ArrayList&lt;OgreEnemy&gt; getTheEnemies() {
          return theEnemies;
      }
  
      public void setTheEnemies(ArrayList&lt;OgreEnemy&gt; theEnemies) {
          this.theEnemies = theEnemies;
      }
  
      public int getNumber() {
          return number;
      }
  
      public void setNumber(int number) {
          this.number = number;
      }
  
      public Ogre getTheOgre() {
          return theOgre;
      }
  
      public void setTheOgre(Ogre theOgre) {
          this.theOgre = theOgre;
      }
  
  
  }//end Square class
  </code></pre>
  <p>I will be making a GUI initialize gameplay but no game logic can go inside it.</p>
  <p>My question then is what is the best way to go about printing the coordinates as in the picture above?</p>
  <ul>
  <li>Should I make a new list with all the coordinates/points?</li>
  <li>And have the map update on each turn to display the coordinates of
  the cell or, if occupied, the object occupying the cell?</li>
  <li>I feel as if a 2d array would have been a better option, but we were instructed to begin grid construction in this manner. <br/></li>
  </ul>
  <p>Obviously, there are much
  more code/classes, but I am most concerned with options for
  displaying coordinates/objects within coordinates.</p>