I need to be able to check if variables a, b, and c from one constructor are equal to a, b, and c from another constructor (Quadratic q). I get the feeling that my copy constructor might be wrong and this could potentially be the problem as well. I'm trying to accomplish this through the last method. Ignore what I have in there now, I'm sure it's completely wrong. I'd appreciate any help I can get. This is what I have so far:
import java.util.Scanner;
public class Quadratic
{
// instance variables - replace the example below with your own
private double a;
private double b;
private double c;
/**
* Assignment constructor
*/
public Quadratic(double aIn, double bIn, double cIn)
{
a=aIn; b=bIn; c=cIn;
}
/**
* Copy constructor of class Quadratic for objects
*/
public Quadratic(Quadratic q)
{
a=q.a;b=q.b;c=q.c;
}
/**
* Default constructor - uses Scanner class.
*/
public Quadratic()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a: ");
double a=in.nextDouble();
System.out.println("Enter b: ");
double b= in.nextDouble();
System.out.println("Enter c: ");
double c= in.nextDouble();
}
/**
* Returns an expression for the quadratic, i.e., 1.0x^2 + 3.0x + 2.0
*/
public String toString()
{
return a+"x^2 + "+b+"x + " + c;
}
/**
* Returns true if a, b, and c all match for this & q; false otherwise.
*/
public boolean equals(Quadratic q)
{
if (Quadratic(q).equalsQuadratic(a,b,c))
return true;
else
return false;
}
}