Question: public class secondOrder { public static void main ( String [ ] args ) { / / declare variables for inputs double a , b

public class secondOrder {
public static void main(String[] args){
//declare variables for inputs
double a, b, c;
//get values from the user
Scanner sc = new Scanner(System.in);
System.out.println("Enter the coefficients a, b, and c: ");
a = sc.nextDouble();
b = sc.nextDouble();
c = sc.nextDouble();
//there two cases for a
if(a ==0){
if(b ==0){
if(c ==0){
System.out.println("There are infinite number og solutions");
}else {//C !=0
System.out.println("There no solutions");
}
}else {//b !=0
System.out.println("The equation is a first order equation and has one solution: "+(-c/b));
}
}else {//a !=0
double D = Math.pow(b,2)-4*a*c;
if(D ==0){
double x =-b/(2*a);
System.out.println("The equation has one double solution "+ x);
}else if(D >0){
double x1=(-b + Math.sqrt(D))/(2*a);
double x2=(-b - Math.sqrt(D))/(2*a);
System.out.println("There are two distinct solutions:
X1="+ x1+"
X2="+ x2);
}else{//D <0
System.out.println("There are no real solutions");
}
}
}
}
Modify the program secondOrder equation to implement it as a class.
With a design of your choice (no Scanner in class definition almost never!!)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!