Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Project: Using Java API Classes Page 1 of 5 Deliverables Your project files should be submitted to Web-CAT by the due date and time specified.
Project: Using Java API Classes Page 1 of 5 Deliverables Your project files should be submitted to Web-CAT by the due date and time specified. In order to avoid a late penalty for the project, you must submit your completed code files to Web-CAT by 11:59 p.m. on the due date. If you are unable to submit via Web-CAT, you should e-mail your project Java files in a zip file to your TA before the deadline. Files to submit to Web-CAT: ExpressionEvaluator.java Space Ticket.java Specifications Overview: You will write two programs this week. The first will compute the value generated by a specified expression and the second will read data for a ticket to a destination in space and then interpret and print the formatted ticket information Expression Evaluator.java Requirements: Calculate the following expression for a value x of type double which is read in from the keyboard, and save the result of the expression in a variable of the type double. You must use the sqrt(), abs() and pow() 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. (3x5 2x3) [16x?| + 1 Next, determine the number of 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 use the indexOf() method from the String class to find the position of the period (i.e., 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 five 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.0####" in your Page 1 of 5 Project: Using Java API Classes Page 2 of 5 DecimalFormat constructor. 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 ExpressionEvaluator program are shown below. Line number Program output Enter a value for x: 1 Result: 0.2 #digits to left of decimal point: 1 #digits to right of decimal point: 1 Formatted Result: 0.2 Line number UWN Program output Enter a value for x: -3.9 Result: 14264.157114937527 # digits to left of decimal point: 5 #digits to right of decimal point: 12 Formatted Result: 14,264.15711 Line number Program output Enter a value for x: 10.5 Result: 9651967.171179585 #digits to left of decimal point: 7 #digits to right of decimal point: 9 Formatted Result: 9,651,967.17118 | Line number Program output Enter a value for x: 12345.6789 Result: 8.851764802663216E26 # digits to left of decimal point: 1 #digits to right of decimal point: 18 Formatted Result: 885, 176, 480,266,321,600,000,000,000.0 When the digits to the right of the decimal in the unformatted result end with E followed by one or more digits (e.g., E26 indicates an exponent of 26), the 'E' should be included in the count of the digits 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 Page 2 of 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started