title: Need Help Finding the intersection of two equations in Java
body: <p>I saw someone else posted this problem but didn't word it properly so he didn't end up receiving any help, so I figured I would try and be more direct.</p>
  
  <p>Here is the problem proposed to us :</p>
  
  <p>// Write and submit your code in a file called Intersect.java. Use the IO module to read inputs. Use System.out.println() to print your answer.</p>
  
  <p>Write a program that calculates the intersection between 2 equations:</p>
  
  <p>a degree-2 (quadratic) polynomial i.e.  </p>
  
  <p>y = dx^2 + fx + g</p>
  
  <p>where d, f, and g are constants</p>
  
  <p>and a degree-1 (linear) equation i.e.</p>
  
  <p>y = mx + b</p>
  
  <p>where m is the slope and b is a constant</p>
  
  <p>The above is just text, not code that could appear in a Java program.</p>
  
  <p>Ask the user for the constant values in each equation. Output the intersection(s) as ordered pair(s) (x,y), or "none" if none exists. Below is an example run.</p>
  
  <p>java Intersect</p>
  
  <p>Enter the constant d:
  5
  Enter the constant f:
  -3
  Enter the constant g:
  2
  Enter the constant m:
  1
  Enter the constant b:
  3</p>
  
  <p>The intersection(s) is/are:
  (1,4)
  (-0.20,2.8)
  //</p>
  
  <p>The main problem is essentially asking us to write a code that asks the user to imput the individual constants and the slope of the two equations, one being a quadratic polynomial and the other being a linear equation in point-slope.</p>
  
  <p>I understand that we have to use the quadratic equation in the code, however I have no idea how to actually code this in.</p>
  
  <p>Once we have had the user imput the constants, in this case 5 (d,f,g,m,b; with m being slope)  we need to have the code run the calculations to imput those constants into the above example ( y = dx^2 + fx + g  |  y = mx + b)  and return either "none" if there is no intersection, or if it does intersect, the ordered pair at which it does intersect (x,y).  </p>
  
  <p>I know already that if 0 is entered as the constants it returns (NaN,NaN) which I also know needs to be re-written to None.</p>
  
  <p>so far I only have the following:</p>
  
  <p>public class Intersect {
      public static void main(String[] args) {</p>
  
  <pre><code>    System.out.println("Enter the constant d:");
      int d = IO.readInt();
  
      System.out.println("Enter the constant f:");
      int f = IO.readInt();
  
      System.out.println("Enter the constant g:");
      int g = IO.readInt();
  
      System.out.println("Enter the constant m:");
      int m = IO.readInt();
  
      System.out.println("Enter the constant b:");
      int b = IO.readInt();
  </code></pre>
  
  <p>If anyone can shed some light on this that would be fantastic, thanks!</p>
  
  <p>EDIT1 :</p>
  
  <p>So far i've changed the code to the following, however, I still don't know how to get it to return to me an answer:</p>
  
  <p>public class Intersect {
      public static void main(String[] args) {</p>
  
  <pre><code>    System.out.println("Enter the constant d:");
      int d = IO.readInt();
  
      System.out.println("Enter the constant f:");
      int f = IO.readInt();
  
      System.out.println("Enter the constant g:");
      int g = IO.readInt();
  
      System.out.println("Enter the constant m:");
      int m = IO.readInt();
  
      System.out.println("Enter the constant b:");
      int b = IO.readInt();
  
  
      //y = dx^2 + fx + g
      //y = mx + b
  
      //mx + b = dx^2 + fx + g
  
      //x^2 * (d)  +   x * ( f - m )  +  ( g - b )
  
      int A = d;
      int B =  f - m;
      int C =  g - b;
  
  
      double x1 = - B + Math.sqrt(  B^2  -  4 * A * C ) / (2 * A);
      double x2 = - B - Math.sqrt(  B^2  -  4 * A * C ) / (2 * A);
  
  
      double y1 = m * x1 + b;
      double y2 = m * x1 + b; 
  </code></pre>
  
  <p>}</p>
  
  <p>Also, eclipse is telling me that x2,y1, and y2 aren't used at all.
  I know I need to use System.out.println()  however I don't understand what I can put there to make the answer an ordered pair.  Also, I tried setting an If statement to have the answer return None instead of NaN however it instead returns, NaN None.</p>