import java.util.*;
public class Project1 {
public static void main(String[] args) {
System.out.println("Enter a,b,c: ");
Scanner input = new Scanner(System.in);
double a1 = input.nextDouble();
double b1 = input.nextDouble();
double c1 = input.nextDouble();
Equsolve Equ = new Equsolve(a1, b1, c1);
Equ.PrintInfo();
}
}
This was main class code.
this one is equation class:
public class Equsolve {
double a;
double b;
double c;
double x2;
double x1;
public Equsolve(double a1, double b1, double c1) {
a = a1;
b = b1;
c = c1;
}
public void delta() {
double delta = (b*b)-(4*a*c);
}
public void x1(double delta){
x1 = ((-b)+(Math.sqrt(delta))/(2*a));
}
public void x2(double delta){
x2 = ((-b)-(Math.sqrt(delta))/(2*a));
}
public void PrintInfo(){
System.out.format("a = %fn", a);
System.out.format("b = %fn", b);
System.out.format("c = %fn", c);
System.out.format("x1 = %fn", x1);
System.out.format("x2 = %fn", x2);
}
}
I was trying to create a class which solves quadratic equations.
But the x1 and x2 are always 0!
I even tried to change the value manually but it’s still 0!
New contributor
Mohamad Ghorbani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.