title: Defining a comparator for a quadratic function object
body: <p>This is my assignment, 
  a) Write a quadraticFunction that represents a quadratic ax^2 + bx + c with int coeffients a, b, c. Provide a constructor with 3 int parameters for a, b, c. Provide a method double valueAt(double x) returns the value of this quadratic function at x. Also provide a toString method.</p>
  
  <p>b) override the equals method quadraticmethod class. two quadraticfunction should be considered equal if their respective coeffiecients are equal</p>
  
  <p>c) Make the function objects comparable. The compareTo should first compare 1 if equal compare b if equal compare c</p>
  
  <p>d) Define a comparator class for comparing two QuadraticFunction objects. Provide two constructors:  a no-argss constructor and a constructor that takes 1 double parameter. When a comparator is created by the no-args constructor, it should compare two quadraticFunction based on their values at x = 0; when a comparator is created by the constructor with a parameter x, it should compare quadraticFunction based on their values at x</p>
  
  <p>Here's my code</p>
  
  <p>I need help with part D, I don't know how to do some of it</p>
  
  <pre><code>    public class Ex4
      {
      int a;
      int b;
      int c;
  
   public Ex4(int x, int y, int z)
   {
      a = x; b=y; c=z;
   }
   public String toString()
   {
      String X="";
      X= X+a+"x^2"+b+"x"+ "+" + c;
      return X;
   }
   public double valueAt(double x)
   {
      return (a*x*x+b*x+c);
   }
   //////// Part B
   public boolean equals( Ex4 qf )
   {
      return(this.a==qf.a &amp;&amp; this.b==qf.b &amp;&amp; this.c==qf.c);
   }
   /////Part c
  //   public int compareTo(Ex4 other)
  
  //   {
  
  //      if (a.equals(other.a))
  //      {
  
  //          if (b.equals(other.b))
  
  //              return c.compareTo(other.c);
  
  //          return b.comapreTo(other.b);
  
  //          }
  
  //    return a.compareTo(other.a);
  
  //  }
  
  public int compareTo(Ex4 other)
  {
      if (a &gt; other.a)
          return 1;
      else if (a &lt; other.a)
          return -1;
      else if (b &gt; other.b)
          return 1;
      else if (b &lt; other.b)
          return -1;
      else if (c &gt; other.c)
          return 1;
      else if (c &lt; other.c)
          return -1;
      else
          return 0;
  }
  ////Part d
  
   public static void main(String[] args)
   {
      System.out.println(new Ex3(1, -5, 6));
   }
  }
  </code></pre>
  
  <p>Also in the uncomment the area of code under part c, it says int cannot be dereferenced on line 29, 31, 32,33, and 35
  Thanks for the help</p>