Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 161: Quadratic Formula Objectives Write a Java Project from scratch Learn how to read input from the user Decompose problem solving to several methods

CSCI 161: Quadratic Formula Objectives Write a Java Project from scratch Learn how to read input from the user Decompose problem solving to several methods Use good naming conventions when creating variables Leverage your improved knowledge of the Java programming language to produce the desired output Overview Write a program that solves quadratic equations and prints their roots. A quadratic equation has the following form: a x 2 + b x + c = 0 where a 0 . There are two solutions to such an equation: x = b b 2 4 a c 2 a Note the symbol, which indicates one solution (root) is obtained by adding the two terms in the numerator, and the other is obtained by subtracting the two terms. Write a method named printQuadraticRoots that prints an equation and its two roots, and call the method in main with the appropriate parameters. You may assume the equation has two real roots and that a 0. Please name your program QuadraticFormula.java Input Specification Use variables a, b, and c to represent the INTEGER coefficients of the equation. These should be read from the user with a Scanner object. Extensively TEST your program with many other values to verify correctness. Input should be in the form: a ==> b ==> c ==> Make sure there is a space before and after the arrow (==>) Output Specification Output the equation along with its two roots. You do NOT need to worry about how many digits follow the decimal point. Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output sample below is for the equation x 2 2 x 4 = 0 Sample Output a ==> 1 b ==> -2 c ==> -4 For the equation "(1)x^2 + (-2)x + (-4) = 0", the roots are x = 3.236068 and x = -1.236068 Note: there are two spaces between the beginning of the line and the x output on the second and fourth lines. There is only one space before the and on the third line. Required Methods Include at LEAST the following methods. You will need to DETERMINE the return types and parameters, and the calling relationship between methods. Only call the discriminant method ONCE so you dont compute the same quantity twice. IMPORTANT: make sure you CAREFULLY read what each method does // Print "For the equation ... the roots are" // followed by the two roots, in the format above // // HINT: look at the required variables to determine the parameters DetermineReturnType printQuadraticRoots (...) // Print a quadratic equation using the following format: // (a)x^2 + (b)x + (c) = 0 // Do NOT print any quotation marks or newline characters // HINT: look at the required variables to determine the parameters DetermineReturnType printEquation (...) // Compute and return the discriminant (b^2 - 4ac) // HINT: look at the required variables to determine the parameters // look at what the discriminant should evaluate to in order // to derive the return type DetermineReturnType calcDiscriminant (...) Hints You may use methods of the Math class. Use WolframAlpha to verify that your program is correct. Ensure your program can handle any equation with real roots. Style Use good programming style: Write comments Choose mnemonic, meaningful variable names (e.g. seconds, minutes) Indent consistently (Ctrl+Shift+F will format your code) Remember the comment block at the top of your program Submission Please name your program QuadraticFormula.java Submit the Java source code file on Autolab under the Quadratic Formula assignment. Grading 20 points will be awarded for having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points. 20 points will be awarded for having proper input from a user. 40 points will be awarded for having methods with correct parameters and return types 20 points will be awarded for having proper output that matches EXACTLY NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100image text in transcribedimage text in transcribed

CSCI 161: Quadratic Formula Objectives Write a Java Project from scratch Learn how to read input from the user Decompose problem solving to several methods Use good naming conventions when creating variables Leverage your improved knowledge of the Java programming language to produce the desired output Overview Write a program that solves quadratic equations and prints their roots. A quadratic equation has the following form: ar? + b3 + c = 0 where a 70. There are two solutions to such an equation: -b4V02 - dac Note the # symbol, which indicates one solution (root) is obtained by adding the two terms in the numerator, and the other is obtained by subtracting the two terms. Write a method named printQuadraticRoots that prints an equation and its two roots, and call the method in "main" with the appropriate parameters. You may assume the equation has two real roots and that a + 0. Please name your program QuadraticFormula.java Input Specification Use variables a, b, and to represent the INTEGER coefficients of the equation. These should be read from the user with a sc anner object. Extensively TEST your program with many other values to verify correctness. Input should be in the form: 2a Make sure there is a space before and after the arrow () Output Specification Output the equation along with its two roots. You do NOT need to worry about how many digits follow the decimal point. Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output sample below is for the equation 22-22-4 0 Sample Output a => 1 b = -2 CE-4 For the equation "(1) x^2 + (-2)x + (-4) = 0", the roots are x = 3.236668 and x = -1.236868 Note: there are two spaces between the beginning of the line and the output on the second and fourth lines. There is only one space before the and on the third line. Required Methods Include at LEAST the following methods. You will need to DETERMINE the return types and parameters, and the calling relationship between methods. Only call the discriminant method ONCE so you don't compute the same quantity twice. IMPORTANT: make sure you CAREFULLY read what each method does 1/ Print "For the equation ... the roots are" followed by the two roots, in the format above // HINT: look at the required variables to determine the parameters Required Methods Include at LEAST the following methods. You will need to DETERMINE the return types and parameters, and the calling relationship between methods. Only call the discriminant method ONCE so you don't compute the same quantity twice. IMPORTANT: make sure you CAREFULLY read what each method does 1/ Print "For the equation ... the roots are" V followed by the two roots, in the format above 1 11 HINT: look at the required variables to determine the parameters DetermineReturnType printQuadraticRoots (...) 1/ Print a quadratic equation using the following format: (a) x^2 + (b)x+ (c) = 0 // DO NOT print any quotation marks or newline characters // HINT: look at the required variables to determine the parameters DetermineReturnType printEquation (...) 1/ Compute and return the discriminant (b^2 - 4ac) // HINT: look at the required variables to determine the parameters look at what the discriminant should evaluate to in order to derive the return type DetermineReturn Type calcDiscriminant (...) Hints You may use methods of the Math class. Use Wolfram Alpha to verify that your program is correct. Ensure your program can handle any equation with real roots. Style Use good programming style: Write comments Choose mnemonic, meaningful variable names (e.g. seconds, minutes) Indent consistently ( Ctrl + Shift + F will format your code) Remember the comment block at the top of your program Submission Please name your program QuadraticFormula.java Submit the Java source code file on Autolab under the "Quadratic Formula assignment. Grading 20 points will be awarded for having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points. 20 points will be awarded for having proper input from a user. 40 points will be awarded for having methods with correct parameters and return types 20 points will be awarded for having proper output that matches EXACTLY NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago