Java help!

hascet

Fully Optimized
Messages
3,218
Code:
/* P1ch3prg2
My name
period 7 */
import java.awt.*;
import java.text.DecimalFormat;
import hsa.Console;

public class P1ch3prg2
{
    static Console c;

    public static void main (String[] args)
    {
        c = new Console ();
        double a, b, c1, x1;
        c.print ("Enter a value for \'a\' ");
        a = c.readDouble ();
        c.print ("Enter a value for \'b\' ");
        b = c.readDouble ();
        c.print("Enter a value for \'c\' ");
        c1 = c.readDouble ();
        x1 = (-b + Math.sqrt (Math.pow (b, 2) - 4 * a * c1)) / (2 * a);
        c.print ("The \"positive\" solution is: ");
        DecimalFormat x = new DecimalFormat ("0.0000");
        c.println (x.format(x1));
    }
}

Then I need to make these changes, but I don't understand any of it lol!

Unit 4 Programs continued page 2 of 2
II. Quadratic Formula Program Revised: (20 points)
Purpose: Modify your P1ch3prg2 (quadratic formula problem) Calculate the discriminant
(b2 - 4ac). If the discriminant is < 0 then “no real roots” is output, if the discriminant = 0 then
calculate the 1 root by -b/2a, and if the discriminant >0 then find both roots.
A) Input: Complete what the input will be (in English words and include its data type): (2 pts)
________________________________________________________________________
B) Output: Complete what the exact 3 outputs will look like (include the inputs):
Note: Use the number sign, #, to represent numbers that can vary from one run to the next.
Use a ÿ indicate a space in a line and use an arrow, off to the left, to indicate each blank line.
Be NEAT as this is the exact output on which you will be graded.
Output if discriminant < 0 Output if discriminant = 0 Output if discriminant > 0
C) Write the algorithm (on a separate sheet) using pseudocode, for the check of the
discriminant (b2 - 4ac). Think of what should be done if the discriminant is
negative, equal to zero, or positive,
Show your teacher the algorithm before doing #6) below. _____________
(teacher signature)
Further specifications:
1) Use appropriate comments in your program:
a) Name of program b) Your name c) Class hour
2) Use meaningful variables and proper indentation for the if/else
3) Use nested if statements
4) Code and enter it into the computer.
5) Compile, run, and debug. Check it with the values:
a = 1, b = 2, c = 5 Output: No real roots
a = 1, b = 2, c = 1 Output: Answer is: -1.0000 // Note the four place precision
a = 1, b = 2, c = -5 Output: Root 1 is: 1.4495
Root 2 is: -3.4495
6) Save as P1ch4prg2
When perfect, show your teacher the coding and output (run), _____________
then turn in this sheet with the algorithm stapled on to it! (teacher signature)
Extra Credit:
Put in a check for a = 0. If zero then state that it is not a quadratic and exit the program.
(*Note: Be sure you tell your teacher that you have done this and to check for it.)
 
you need to edit your program to do what the teacher asks

they're asking you to evaluate b2 - 4ac for certain conditions and provide results depending on the condition it satisfies. the output methods are a tad confusing if you're confused on that part please ask your teacher to clarify as it seems to be an important part of the assignment (personally I think it's trivial).

it also asks for a float, to 4 decimal places.
 
Ya, I figured it out a last week lol, so I don't need help anymore, it actually wasn't as difficult as I expected just used if else statements and found roots. I'de post the program, but its at school, and I'm not lol, so I'm out of luck :p
 
Back
Top Bottom