Write a Java program that solves a set of quadratic equations as per Requirement #1 (without...

80.2K

Verified Solution

Question

Programming

Write a Java program that solves a set of quadratic equations asper Requirement #1 (without using global variables), and reads aninteger number entered in the command line, as follows: > javaprogram_name input_number and depending on the value of this numberdoes the following:

1) If the number entered is positive, the program shall solve(running in a loop) as many quadratic equations of the followingform, as the input_number tells:

a * x2 + b * x + c = 0

where coefficients a, b and c are double values, entered fromthe keyboard as per Requirement #3.

2) If the input number entered in the command line is notpositive, the program shall print the following message to thescreen and exit:

A positive value shall be entered in the command line.

3) The values of coefficients a, b and c, as listed inRequirement #1, shall be read from the keyboard by the program withthe following message on the screen, each time a new coefficient isneeded:

Please enter the next coefficient of a quadratic equation:

4) If the coefficient a is a zero, the program shall display thefollowing message on the screen (first line) repeating the requestfor another value of a (second line):

Coefficient a cannot be a zero. Enter the correct value. Pleaseenter the next coefficient of a quadratic equation:

5) When the program solves the quadratic equation (calculatesthe roots), as per Requirement #1, the following output shall bedisplayed on the screen:

Quadratic equation with the following coefficients

a: ; b: ; c: has

the following roots: and

6) In case the quadratic equation for given coefficients doesnot have roots, the program shall print the following message, andcontinue operation for the next set of coefficients:

Quadratic equation with the following coefficients:

a: ; b: ; c: does nothave roots

Answer & Explanation Solved by verified expert
4.1 Ratings (741 Votes)
Code is Given Belowimport javautilScannerpublic class Quadratic public static void mainString args creating scanner object to getinput from user Scanner    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students