title: Java Quadratic Equation Class
body: <p>I have yellow squiggly lines under my coeffA = in.nextDouble(); coeffB = in.nextDouble(); and coeffC = in.nextDouble(); in my tester class and can't figure out why? Also, when I run my tester class it always returns 0.0 and -0.0 I can't seem to get any calculations at all other than 0. Any help would be appreciated!</p>
  
  <p>Directions:
  I have to write a program that prints all real solutions to the quadratic equation ax^2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminant b^2 - 4ac is negative, display a message stating that there are no real solutions. Implement a class QuadraticEquation whose constructor receives the coefficients a, b, c of the quadratic equation. Supply methods getSolution1 and getSolution2 that get the solutions, using the quadratic formula, or 0 if no solution exists. The getSolution1 method should return the smaller of the two solutions. Supply a method boolean hasSolutions() that returns false if the discriminant is negative.</p>
  
  <pre><code>public class QuadraticEquation
  {
  
  double coeffA;
  double coeffB;
  double coeffC;
  private boolean hasSolutions;
  double discriminant;
  
  public QuadraticEquation()
  {
      coeffA = 0;
      coeffB = 0;
      coeffC = 0;
  }
  
  /**
  Constructs a quadratic equation and get 2 solutions
  @param coefficientA coefficient a of quadratic equation
  @param coefficientB coefficient b of quadratic equation
  @param coefficientC coefficient c of quadratic equation
  */
  public QuadraticEquation(double coefficientA, double coefficientB, double coefficientC)
  {
      coeffA = coefficientA;
      coeffB = coefficientB;
      coeffC = coefficientC;
      discriminant = (Math.pow(coeffB, 2) - 4 * coeffA * coeffC);
  }
  
  /**
   * Checks if there is a solution
   * @return true if there is a real solution
   */
  public boolean hasSolutions()
  {
  if(discriminant &lt; 0)
      hasSolutions = false;
  else
      hasSolutions = true;
  return hasSolutions;
  }
  
  /**
   * Returns the first solution to the quadratic equation
   * @return the first solution
  */
  public double getSolution1()
  {
      return (-coeffB + Math.sqrt(discriminant) / 2 * coeffA);
  }
  
  /**
   * Returns the second solution to the quadratic equation
   * @return the second solution
  */
  public double getSolution2()
  {
      return (-coeffB - Math.sqrt(discriminant) / 2 * coeffA);
  }
  
  }
  </code></pre>
  
  <p>Here is my tester class:</p>
  
  <pre><code>import java.util.Scanner;
  
  /**
   This program tests the QuadraticEquation class.
  */
   public class QuadraticEquationTester
  {
  
  public static void main(String[] args)
  {
     Scanner in = new Scanner(System.in);
  
  
      System.out.print("Please enter coefficient a: ");
      double coeffA = in.nextDouble();
      System.out.print("Please enter coefficient b: ");
      double coeffB = in.nextDouble();
      System.out.print("Please enter coefficient c: ");
      double coeffC = in.nextDouble();
  
      QuadraticEquation equation = new QuadraticEquation(0, 0, 0);
  
          if (equation.hasSolutions())
          System.out.println(equation.getSolution1());
          if (equation.hasSolutions());
          System.out.println(equation.getSolution2());
          System.exit(0);
  
  
  
    in.close();
   }
   }
  </code></pre>