Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-09-2007, 02:07 PM   #1
Fully Optimized
 
hascet's Avatar
 
Join Date: Jul 2006
Posts: 3,218
Default Java help!

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!

Quote:
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.)
__________________

__________________
www.crazycomputers.org
hascet is offline   Reply With Quote
Old 11-09-2007, 02:10 PM   #2
BSOD
 
Join Date: Jun 2007
Posts: 2,505
Default Re: Java help!

I dont get what you need. do you need to download it or something.
__________________

Dark Night is offline   Reply With Quote
Old 11-09-2007, 02:12 PM   #3
Fully Optimized
 
hascet's Avatar
 
Join Date: Jul 2006
Posts: 3,218
Default Re: Java help!

Quote:
Originally Posted by Dudemcbob0876 View Post
I dont get what you need. do you need to download it or something.
No, its for a class at school...
__________________
www.crazycomputers.org
hascet is offline   Reply With Quote
Old 11-09-2007, 02:12 PM   #4
BSOD
 
Join Date: Jun 2007
Posts: 2,505
Default Re: Java help!

O, I dont understand it eihter.
Dark Night is offline   Reply With Quote
Old 11-18-2007, 07:11 PM   #5
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: Java help!

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.
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 11-18-2007, 08:01 PM   #6
Fully Optimized
 
hascet's Avatar
 
Join Date: Jul 2006
Posts: 3,218
Default Re: Java help!

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
__________________

hascet is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 03:33 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0