Question
Need help with Java Programming! Need to create a java program script for the instructions below and I am just stuck. You are working for
Need help with Java Programming!
Need to create a java program script for the instructions below and I am just stuck.
You are working for a company that writes Android apps in Java. The client wants an app that will help a user see how much of a tip he/she should leave. The client wants to see a quick prototype that runs on a computer console so he can determine that your company really understands what he wants. You are selected to write this prototype. It will be turned into an Android app by someone else on your team later, after the client approves your prototype. You need to write a program in Java that will tell the user how much to tip a waiter or waitress at a restaurant. You will just make it run on your computer console instead of on an Android device.
Description : This program requests the meal cost and tip percentage from the user, calculates the monetary amount of the tip, rounds the tip to the nearest penny, calculates the total meal cost, and displays those values in dollars and cents. It uses the printf statement to format those numbers so that only 2 digits are displayed to the right of the decimal point. */ 3.
Use comments liberally to document exactly what you are doing in the program, especially explain about the rounding in #11.
4. Use descriptive variable names in camel-case with the first letter in lowercase.
5. Ask the user for the total cost of the meal.
6. Read in a double number and assign it to a variable of type double.
7. Ask the user for the percent tip.
8. Read in an integer number and assign it to a variable of type integer.
9. Divide that percent tip by a double 100 to get the tip rate in a decimal form instead of percent and assign that to a variable of type double. 10. Multiply the variable that represents the cost of the meal by the variable that represents the tip rate in decimal form. This will be the tip amount in dollars and cents. Assign this result to a variable of type double.
11. Extra Credit: Round that last result to the nearest cent using the Math.round method described in Chapter 4 amount in the original variable for the tip amount in dollars and cents. Note that if you use the printf statement in #12 correctly, it will be displayed as rounded to the nearest cent, but the variable itself will NOT have been rounded unless you use Math.round or some other rounding technique. Be sure to make a clear comment for this step.
12. Tell the user how much the tip should be in dollars and cents. Make sure that you display exactly 2 digits after the decimal point (this will cause the display amount to round, but the variable will NOT be changed by this). You will need to use the printf statement with format specifier Tip amount: $%.2f , or you could use %n instead of , but all other languages use , which is the end of line character. The backslash indicates an escape character, which, when combined with another character, creates one special character.
13. Add that tip amount to the total cost of the meal and store that total in the same variable as the total cost of the meal. Use the addition assignment operator += to do this.
14. Tell the user what the new total is. Make sure that you display exactly 2 digits after the decimal point (this will cause the display amount to round, but the variable will NOT be changed by this). Again, use printf with format specifier Meal total : $%.2f . Be sure to put two blanks after the colon so that your $ signs line up.
Sample Run: Enter total meal cost (example 43.37): 54.27 Enter tip in percent (example 15 means 15%): 17 Tip amount: $9.23 Meal total : $63.50 Notes: If your tip amount ends up as zero, reread instruction #8 above carefully because it is likely that you did integer arithmetic instead of floating-point arithmetic. To format the dollar and cents, read Section 4.6 in your Liang book about the printf statement. That will tell you how to make the output have exactly two digits after the decimal point.
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