I’m making a Java program that can solve the roots using the quadratic equation by giving a, b, and c.
Here is the main code:
//main file
class Call
{
public static void main(String args [])
{
double a=Double.parseDouble(args[0]);
double b=Double.parseDouble(args[1]);
double c=Double.parseDouble(args[3]);
Receiver r = new Receiver(".");
if (r.determine(a,b,c)=true)
{
double root1=r.Root;
double root2=r.Root2;
System.out.println("The first root is +root1");
System.out.println("The second root is +root2");
}
else
{
System.out.println("Not a number");
}
}
}
Now here’s the class I’m trying to call but couldn’t.
class Receiver
{
public boolean determine(double a, double b, double c)
{
double value=b*b-4*a*c;
if (value<0)
return false;
else
return true;
}
public double Root(double a, double b, double c)
{
double value=b*b-4*a*c;
double root=(-b+ Math.sqrt(value))/(2*a);
return root;
}
public double Root2(double a, double b, double c)
{
double value=b*b-4*a*c;
double root2=(-b- Math.sqrt(value))/(2*a);
return root2;
}
}
I made sure that I compiled the Receiver.java already. But when I compile Call.java, I get this error:
Call.java:14:error:cannot find symbol
Receiver r= new Receiver();
symbol: class Receiver
location: class Call
Note that I haven’t found constructor
public Receiver(String arg), and you’re using it like this, aren’t you missing that?If you’re compiling those by yourself from command line ensure, these steps:
Create package with those class
Compile those files so that package is created in class structure
(this will create folders in current location like
/com/mypackage/app/)Run the Call class from current location by it’s package name