title: Create Magic Square Function and write to file
body: <p>I have a constructor to create a MagicSqaure</p>
  
  <pre class="lang-java prettyprint-override"><code>private int[][] matrix;
  private boolean isSquare;
  
  public MagicSquare (String filename, int n) throws IOException
      {
          if (n % 2 != 1)
          {
              throw new RuntimeException("Dimensions must be odd");
          }
          else
          {
              int row = n-1;
              int col = n/2;
              this.matrix[row][col] = 1;
  
              for (int i = 2; i &lt;= n*n; i++) {
                  if (this.matrix[(row + 1) % n][(col + 1) % n] == 0) {
                      row = (row + 1) % n;
                      col = (col + 1) % n;
                  }
                  else {
                      row = (row - 1 + n) % n;
  
                  }
                  this.matrix[row][col] = i;
              }
          }
  
          File file = new File(filename);
          PrintWriter outFile = new PrintWriter(new FileWriter(file));
          //Need to write items to file here
          outFile.close();
      }
  </code></pre>
  
  <p>I'm a little confused in two spots on this assignment</p>
  
  <ol>
  <li>I am not exactly sure how to take this 2-d Array and convert it into a text file like so</li>
  </ol>
  
  <pre><code>3 //this first line is the dimension(s) of the magic square
  123
  456
  789
  </code></pre>
  
  <ol start="2">
  <li>When I try to run the code without the file creation and simply look to generate a magicSquare from my driver class </li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>public class MagicSquareDriver {
      public static void main (String[] args)
      {
          if (args[0].equalsIgnoreCase("-create"))
          {
              MagicSquare square = new MagicSquare(args[1], Integer.parseInt(args[2]));
  
              System.out.println(square.toString());
          }
  
          else if (args[0].equalsIgnoreCase("-check"))
          {
              MagicSquare square = new MagicSquare(args[1]);
  
              System.out.println(square.toString());
          }
          else {
              throw new IllegalArgumentException();
          }
  
      }
  }
  </code></pre>
  
  <p>I end up with the following error: </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at MagicSquare.&lt;init&gt;(MagicSquare.java:53)
      at MagicSquareDriver.main(MagicSquareDriver.java:6)
  </code></pre>