Hello, I am new to programming and would love to get some help. I am try to make a simple program in eclipse to work out few basic equations. I have made 2 packages, "Equations", and "Workspace".
This is the class "quadraticEquation" in equations package.
package Equations;
import java.util.*;
public class quadraticEquation {
//ax^2 + bx + c = 0
double a,b,c;
Scanner input= new Scanner(System.in);
void calculateQuadEq() {
System.out.println("Enter a");
a = input.nextDouble();
System.out.println("Enter b");
b = input.nextDouble();
System.out.println("Enter c");
c = input.nextDouble();
double z = Math.pow(b, 2) - (4*a*c);
if(z<0) {
System.out.println("This equation has no real roots");
} else if(z==0) {
double m = -b/(2*a);
System.out.println("There are 2 equal roots to this equation, " + m + " and " + m);
} else if(z>0) {
double m = (-b + (Math.pow(b, 2) - 4*a*c))/2*a;
double n = (-b - (Math.pow(b, 2) - 4 *a*c))/2*a;
System.out.println("There are 2 real roots to this equation, " + m + " and " + n);
}
}
}
I am successfully able to run the variable calculateQuadEq
in the same package (have tried) but when it comes to a different package, I am not able to. I tired importing the class file like this.
What can I do to achieve this?