I am working on a school assignment. I am supposed to implement a class and supply the methods getSolution1 and getSolution2. However, I am having 2 issues with my code that I cannot figure out.
Issue #1 is on this line:
solution1= ((-1*b)/> + Math.sqrt(Math.pow(b,2)-(4*a*c)));
The compiler is telling me: Syntax error on token ">", delete this token. I can't figure out if I am doing something wrong on my syntax.
Issue #2 is on the ouput line:
String quadEquation= "The quadratic equation is "+ a + Math.pow(("x"),2) + " + " + b+"x"+ " + " + c+ " =0";
Under the Math.pow I get an error that says: The Method pow is not applicable for the arguments String
Here is my entire code:
public class QuadraticEquation
{
double a;
double b;
double c;
double solution1;
double solution2;
QuadraticEquation (double a, double b, double c){
a= this.a;
b= this.b;
c= this.c;
}
public boolean hasSolution (){
if ((Math.pow(b,2))- (4*a*c)<0){
return false;
}
else
{
return true;
}
}
public double getSolution1 (double a, double b, double c)
{
if (hasSolution){
solution1= ((-1*b) + Math.sqrt(Math.pow(b,2)-(4*a*c))) / 2*a;
return solution1;
}
}
public double getSolution2 (double a, double b, double c){
if (hasSolution){
solution1= ((-1*b) - Math.sqrt(Math.pow(b,2)-(4*a*c))) / 2*a;
return solution2;
}
}
public String toString (double a, double b, double c){
String quadEquation= "The quadratic equation is "+ a + "x^2" + " + " + b+"x"+ " + " + c+ " =0";
return quadEquation;
}
}
Since this is a school assignment, I am looking for guidance on solving this problem.
Thank you.