My job is to create a quadratic class containing four class methods.
One method being plusRoot() which returns the root when the quadratic formula uses plus sign (-b+squarerootof D) / 2a
Another being minusRoot() which returns the root when the quadratic formula uses minus sign (-b-squarerootof D) / 2a
A discriminant method which returns (b^2 - 4ac)
The program starts at the main method which asks user for constants a, b, and c then uses all the other methods to output the roots. This is what I have created.
package chapter3Codes;
import java.util.Scanner;
public class QuadraticClass {
static double d;
static double mroot;
static double proot;
public final static void main(String[] args) {
System.out.println("Enter constants a, b, and c");
Scanner scn = new Scanner (System.in);
a = scn.nextDouble();
Scanner scn1 = new Scanner (System.in);
b = scn1.nextDouble();
Scanner scn2 = new Scanner (System.in);
c = scn2.nextDouble();
plusRoot proot = new plusRoot();
minusRoot mroot = new minusRoot();
System.out.println ("The roots are" + proot + "and" mroot);
}
public static double plusRoot (double a, double b, double c){
double proot;
proot = -b + Math.sqrt(d)/ 2*a;
return proot ;
}
public static double minusRoot (double a, double b, double c){
double mroot;
mroot = -b - Math.sqrt(d)/ 2*a;
return mroot ;
}
public static double Disc (double a, double b, double c){
d = Math.pow(b, 2) - 4*a*c;
return d ;
}
}
I am getting errors such as a, b, and c cannot be resolved to a variable and plusRoot and minusRoot cannot be resolved to a type. What am I doing wrong?