title: Making an ASP.NET MVC polynomial root finder
body: <p>So I've just been experimenting with ASP.NET MVC and I'm really starting to like the way everything has one single purpose (as far as the separation of purpose between the models, views and controllers) but I'm still having some trouble applying my basic knowledge to a somewhat practical purpose.</p>
  
  <p>So, I was thinking of trying to create an ASP.NET MVC version of my original JavaScript polynomial root finder.  It should be relatively simple enough.  Obviously it's not going to solve for all roots of every single degree (at least at the moment) but I'm at least trying to get Quadratic-Quartic.</p>
  
  <p>So, I have 1 Controller in addition to my <code>HomeController</code>.  This is called <code>CalculateController</code> and will handle all of the controlling related to any pages dealing with calculating for roots of a certain type of Polynomial.</p>
  
  <p>Therefore, I have 3 Views, 1 for each of the different kind of polynomial, <code>Quadratic.aspx</code>, <code>Cubic.aspx</code> and <code>Quartic.aspx</code>.</p>
  
  <p>Now, I was thinking I would need a Model here to handle my "business logic" in this case, the actual computing and algebraic calculating of the roots.</p>
  
  <p>This is where I need some feedback.</p>
  
  <p>Should I create one Calculate class?  That is what I have at the moment.  In the class, I declare 5 different instance string variables (I think that's the correct terminology):</p>
  
  <pre><code>public int aValue;
  public int bValue;
  public int cValue;
  public int dValue;
  public int eValue;
  </code></pre>
  
  <p>These will store the values of each of the terms.  Now, is this a bad idea, considering that Quadratic and Cubic won't be using all of these instance fields?  If so, then I could just create separate classes for each separate polynomial type.</p>
  
  <p>OK, now, I also have to receive some input from my form in order to assign the inputted values into these variables.</p>
  
  <p>I'm a little stumped about how I should do this.</p>
  
  <p>I have a form here on my quadratic view:</p>
  
  <pre><code>&lt;% using(Html.BeginForm("QuadraticForm", "Calculate")) %&gt;
  &lt;% { %&gt;
      a: &lt;%= Html.TextBox("quadraticAValue") %&gt;
      &lt;br /&gt;
      b: &lt;%= Html.TextBox("quadraticAValue") %&gt;
      &lt;br /&gt;
      c: &lt;%= Html.TextBox("quadraticAValue") %&gt;
      &lt;br /&gt;
      &lt;input type="submit" id="quadraticSubmitButton" /&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>Very simple, very basic.</p>
  
  <p>Now, how should assign these inputted integers into a new object of the <code>Calculat</code>e class through a <code>Quadratic()</code> method?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>OK, I have some more knowledge than before due to some research, so I'll leave the original question in its entirety above, and update below with some of the info I found out:</p>
  
  <p>I'm going to have a separate class in the Models folder for each different type of polynomial.  Currently, I'm experimenting with the <code>QuadCalc.cs</code> file, the Model for the Quadratic Polynomials.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace RootFinder.Models
  {
      public class QuadCalc
      {
          public double quadraticAValue { get; set; }
          public double quadraticBValue { get; set; }
          public double quadraticCValue { get; set; }
  
          public void QuadCalculate(double quadraticdAValue, double quadraticBValue, double quadraticCValue, out double x1, out double x2)
          {
              //Quadratic Formula: x = (-b +- sqrt(b^2 - 4ac)) / 2a
  
              //Calculate the inside of the square root
              double insideSquareRoot = (quadraticBValue * quadraticBValue) - 4 * quadraticdAValue * quadraticCValue;
  
              if (insideSquareRoot &lt; 0)
              {
                  //There is no solution
                  x1 = double.NaN;
                  x2 = double.NaN;
              }
              else
              {
                  //Compute the value of each x
                  //if there is only one solution, both x's will be the same
                  double sqrt = Math.Sqrt(insideSquareRoot);
                  x1 = (-quadraticBValue + sqrt) / (2 * quadraticdAValue);
                  x2 = (-quadraticBValue - sqrt) / (2 * quadraticAValue);
              }
          }
      }
  }
  </code></pre>
  
  <p>In the code above, I get and set the values of the forms (not really sure how the whole <code>string</code> to <code>double</code> thing is gonna work out, but we can worry about that later xD) and then use those as parameters of a method built around the oh so famous quadratic "formula".</p>
  
  <p>Now, in my <code>Calculate</code> controller, this is my code which applies to the Quadratics:</p>
  
  <pre><code>    [AcceptVerbs(HttpVerbs.Get)]
      public ViewResult Quadratic()
      {
          return View();
      }
  
      [AcceptVerbs(HttpVerbs.Post)]
      public ViewResult Cubic(QuadCalc boss)
      {
          return View();
      }
  </code></pre>
  
  <p>Now, in the above code, instead of <code>boss</code> what should I place here?  I cannot leave it just omitted but I believe it should be the name of an object?  Problem is, I never specified an object in my Model, should I do that?</p>