FormulaEvaluator.java Requirements: Evaluate the following expression for any value of the variable x, and save the result in a variable of the type double. You must use the abs(), pow(), and sqrt() methods of the Math class to perform the calculation. You may use a single assignment statement with a somewhat large expression, or you may break the expression into multiple assignment statements. The latter may be easier to debug if you are not getting the correct result. (9x² + 7x² +5x+3)² (√8x² − 6x² + 4x² +1|20x|+1) Next, determine the number of digits to the left and to the right of the decimal point in the result. [Hint: You can convert the double variable into a String variable using the static method Double.toString(result). Then, on this String variable use the indexOf() method from the String class to find the position of the decimal point ("") and use the length() method to find the length. Knowing the location of the decimal point and the length of the String, you should be able to determine the number of digits on each side of the decimal point.] Finally, the result should printed using the class java.text.Decimal Format so that to the right of the decimal there are at most three digits and to the left of the decimal each group of three digits is separated by a comma in the traditional way. Also, there should also be at least one digit on each side of the decimal (e.g.. zero should be printed as 0.0 rather than 0.000).

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
• FormulaEvaluator.java
Requirements: Evaluate the following expression for any value of the variable x, and save the
result in a variable of the type double. You must use the abs(), pow(), and sqrt() methods of the
Math class to perform the calculation. You may use a single assignment statement with a
somewhat large expression, or you may break the expression into multiple assignment statements.
The latter may be easier to debug if you are not getting the correct result.
5x +3} ( √8x* — 6x²³ + 4x² + |20x+1)
(9x³+7x² +5x+3)
Next, determine the number of digits to the left and to the right of the decimal point in the result.
[Hint: You can convert the double variable into a String variable using the static method
Double.toString(result). Then, on this String variable use the indexOf() method from the String
class to find the position of the decimal point (".") and use the length() method to find the length.
Knowing the location of the decimal point and the length of the String, you should be able to
determine the number of digits on each side of the decimal point.]
Finally, the result should printed using the class java.text.DecimalFormat so that to the right of
the decimal there are at most three digits and to the left of the decimal each group of three digits
is separated by a comma in the traditional way. Also, there should also be at least one digit on
each side of the decimal (e.g., zero should be printed as 0.0 rather than 0.000).
Transcribed Image Text:• FormulaEvaluator.java Requirements: Evaluate the following expression for any value of the variable x, and save the result in a variable of the type double. You must use the abs(), pow(), and sqrt() methods of the Math class to perform the calculation. You may use a single assignment statement with a somewhat large expression, or you may break the expression into multiple assignment statements. The latter may be easier to debug if you are not getting the correct result. 5x +3} ( √8x* — 6x²³ + 4x² + |20x+1) (9x³+7x² +5x+3) Next, determine the number of digits to the left and to the right of the decimal point in the result. [Hint: You can convert the double variable into a String variable using the static method Double.toString(result). Then, on this String variable use the indexOf() method from the String class to find the position of the decimal point (".") and use the length() method to find the length. Knowing the location of the decimal point and the length of the String, you should be able to determine the number of digits on each side of the decimal point.] Finally, the result should printed using the class java.text.DecimalFormat so that to the right of the decimal there are at most three digits and to the left of the decimal each group of three digits is separated by a comma in the traditional way. Also, there should also be at least one digit on each side of the decimal (e.g., zero should be printed as 0.0 rather than 0.000).
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT