(1) Prompt the user to input a the coefficients of the quadratic equation and print out the equation in standard form: ax^2+bx+c=0 (2 pts)

Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user’s input value is shown on the next line, but such values don’t actually appear as output when the program runs.

a: 2 b: 10 c: -3.2 Equation: 2.0x^2+10.0x+-3.2=0

(2) Calculate the roots of the equation. If a=0, print a message indicating the equation is not a valid quadratic equation. Otherwise, calculate the roots based on the discriminant of the quadratic formula. When the discriminant is 0, print out the single real root. When the discriminant is positive, print out the two real roots. Note: print the smaller root first. When the discriminant is negative, calculate the real and imaginary parts of the complex roots separately and then print the roots in standard complex ‘a+bi’ form. Note: print the complex root with the +bi first. (8 pts)


a: 2 b: 10 c: 12 Equation: 2.0x^2+10.0x+12=0 There are two real roots. x = -2.0 x = -3.0

Code will be typed in “Type your code here”:

public class Quadratic {
   public static void main(String[] args) {
      /* Type your code here. */

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *