mkdir ~/cs170/lab7 # make lab directory cd /home/cs170001/share/labs/lab7 # Go to share folder with lab5 cp * ~/cs170/lab7 # Make a copy to your folder cd ~/cs170/lab7 # Go back to your lab folder
I believe that you have work enough with BlueJ to turn Non-BlueJ Java projects into a BlueJ one.
Your task is to write the following program in the ABC.java file. The program first reads in 3 decimal numbers a, b and c, and then computes and prints the solution of the quadratic equation
ax^{2} + bx + c = 0
-------------------- -b + \/ b * b - 4 * a * c x1 = ---------------------------- 2 * aand
-------------------- -b - \/ b * b - 4 * a * c x2 = ---------------------------- 2 * a
There are 1 real valued solution if the discriminant b^{2} - 4ac is equal to zero:
-b x1 = -------- 2 * a
There are 2 complex valued solutions if the discriminant b^{2} - 4ac is less than zero:
-------------------- -b \/ 4 * a * c - b * b x1 = --------- + ------------------------ i 2 * a 2 * aand
-------------------- -b \/ 4 * a * c - b * b x2 = --------- - ------------------------ i 2 * a 2 * aNOTE:
The way to print a complex root is:
Write a program that reads in 3 decimal numbers a, b and c, and then computes and prints the solution of the quadratic equation.
In particular, if the discriminant is 0, the program must print ONE SINGLE value only.
-2.0(You program MUST NOT print -2.0 twice)
Furthermore, if the discriminant is less than 0, the program must print the complex number with the letter "i" appended to the imaginary part.
-0.5 + 0.8660254037844386 i -0.5 - 0.8660254037844386 i
If you can, avoid typing - cut and paste statements that you can use from old programs into your new program.
You can use many statements from this program: click here
-0.2679491924311228 -3.732050807568877
-2.0
-0.5 + 0.8660254037844386 i -0.5 - 0.8660254037844386 i
the real part: realpart = -b / (2*a) the imaginary part: imgpart = Math.sqrt(4 * a * c - b*b)/ (2 * a)separately.
To print the complex number, you use:
System.out.println( realpart + " + " + imgpart + " i");
cd ~/cs170/lab7 /home/cs170001/turnin ABC.java lab7