Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions