Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use java Specifications Overview: You will write two programs this week. The first will solve for the result of a specified expression, and the

please use java
image text in transcribed
image text in transcribed
Specifications Overview: You will write two programs this week. The first will solve for the result of a specified expression, and the second will read data for an event and then interpret and print the formatted event information. - Solver.java Requirements: Solve for the result of the expression in the formula below for a value x of type double which is read in from the keyboard, and save the result in a variable of the type double. You must use the pow (), sqrt (), and abs () methods of the Math class to perform the calculation. You may use a single assignment statement with a single expression, or you may break the expression into appropriate multiple assignment statements. The latter may easier to debug if you are not getting the correct result. result=(2x+4)11x4+9x3+7x2+5x+4 Next, determine the number of characters (mostly digits) to the left and to the right of the decimal point in the unformatted result. [Hint: You should consider converting the type double result into a String using the static method Double. tostring (result) and storing it into a String variable. Then, on this String variable invoke the indexOf (". ") method from the String class to find the position of the period (i.c., decimal point) and the length () method to find the length of the String. Knowing the location of the decimal point and the length, you should be able to determine the number of digits on each side of the decimal point.] Finally, the result should be printed using the class java.text.DecimalFormat so that to the right of the decimal there are at most four 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., 0 should be printed as 0.0 ). Hint: Use the pattern "\#, \#\#\# . 0. when you create your DecimalFormat object. However, make sure you know what this pattern means and how to modify and use it in the future. Design: Several examples of input/output for the Solver program are shown below. When the characters to the right of the decimal in the unformatted result end with E followed by one or more digits (e.g., E11 indicates an exponent of 11), the ' E ' should be included in the count of the characters to the right of the decimal point. Code: In order to receive full credit for this assignment, you must use the appropriate Java API classes and method to do the calculation and formatting. It is recommended as a practice that you do not modify the input value once it is stored. Test: You will be responsible for testing your program, and it is important to not rely only on the examples above. Assume that the amount entered can be any positive or negative floating-point number

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

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago