Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I get my toString Method to work?

843789Mar 8 2010 — edited Mar 8 2010
Hello 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2010
Added on Mar 8 2010
2 comments
221 views