Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The lab this week focuses on implementing a simple tipping app by using input dialog boxes and conditional code to determine the amount of tip

The lab this week focuses on implementing a simple tipping app by using input dialog boxes and conditional code to determine the amount of tip to leave for a meal. This lab requires understanding how to declare constants, display input and message dialog boxes, and write if-else if-else statements. 1. Since the program uses input and message dialog boxes, import the JOptionPane class.

2. Declare the following variables and constant: a. A String that will hold the users input from each of two different input dialog boxes b. A double variable for the cost of the meal that can be initialized to 0 c. An int variable that will hold the users selection from a set of options in one of the input dialog boxes that can be initialized to 0 d. A constant double for the sales tax of 6.75% that will be applied to the meal cost (keep in mind this should be written as a decimal rather than a percentage)

3. Display an input dialog box asking the user how much the meal cost. After storing the users input into the String variable, convert the input to a double and store it into the variable for the cost of the meal.

4. Multiply the cost of the meal by 1 plus the sales tax and store the result back into the variable for the cost of the meal. (Hint: This can be done with a combined assignment operator.)

5. Display an input dialog box asking the user to select from one of three options: leave 15%, leave 20%, or round to the nearest dollar above 15%. After storing the users input into the String variable, convert the input into an int and store it into the variable for the users selection.

6. Based on the users selection, you will choose from one of three options by using if-else if-else statements: a. If the user enters 1, this means they are leaving 15%. b. Else if the user enters 2, this means they are leaving 20%. c. Else, the user must have entered 3. This means they are leaving the nearest whole dollar amount greater than 15%. For example, if the meal with a 15% tip would be $15.26, they are going to leave $16.00.

7. For options 1 and 2 (part a and b of step 6), multiply the cost of the meal by 1 plus the specified tip amount and store the result back into the variable for the cost of the meal. For option 3 (part c of step 6), you will multiply the cost of the meal by 1 plus the 15% tip amount and then use the Math.ceil(amount) method to round the result up to the nearest whole number.

8. After calculating the total cost of the meal, include a message dialog box stating the total cost to the user.

_______________________________________________________________________________________________

I hope someone can get back on this soon. I am having so much trouble wrapping my head around this.

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions