How do I get my toString Method to work?
843789Mar 8 2010 — edited Mar 8 2010Hello all, I'm new to Java. I've been taking a class on it but it hasn't really been doing much to help me understand how to do stuff in it, and we're doing this class that solves quadratic functions:
public class QuadraticFunction
{
private int varA, varB, varC;
public QuadraticFunction(int a, int b, int c)
{
varA = a;
varB = b;
varC = c;
}
public double valueAt(double x)
{
return varA * x * x + varB * x + varC;
}
public String toString()
{
String func = varA + "x^2";
if(varB < 0 && varC < 0)
return "" + varA + "x^2" + Math.abs(varB);
}
}
Basically, I have it set up, but I really don't understand how to get it to work properly, as you can see by my toString it's a total mess, I'd really like it if someone could help me by explaining how to set it up.
Thanks, in advanced.