Write a program that calculates tip amount from a restaurant bill. You enter the
ID: 3537874 • Letter: W
Question
Write a program that calculates tip amount from a restaurant bill. You enter the bill amount and the program will
calculate the tax (10%) and fill out the amount for Tax and Total before Tip. Tip Percent is a Combo box which you select
a tip percentage. The tip percentage will be typed in the Item property of Tip Percent Combo box. Once tip percent has
been selected, you can click on the button (Calculate Tip) to display the tip.
In this program, you will create a heading label, 5 labels associated with 5 text boxes and one button. See the figure
below as reference. You need to create 2 event handlers which are
1. Bill Amount text box TextChanged event
a. Validate the number is not negative
b. Validate the input is number, not letters
c. Once a good input is received, update the tax box, bill before tip box
2. Calculate tip button Click event
a. Validate bill amount has been entered
b. Validate that Tip percentage has been selected
c. Calculate tip and display it in tip text box.
Some other property changes
1. The textbox for tax, bill before tip, and tip should be read only
2. Tip percentage are fixed 3 values, 15%, 18% and 20%
Explanation / Answer
package javaapplication3; import javax.swing.JOptionPane; /** This program demonstrates using dialogs with JOptionPane. */ public class Restaurant { public static void main(String[] args) { inputString; //For reader's input int total; // The user's total bill. int taxAmount; //6.75 of the user's total bill int totalMeal; //Bill after tax has been added int tip; // 15 percent of the totalMeal int overall; // The total including tax and tip // Get the user's total bill. inputString = JOptionPane.showInputDialog("What is " + "the total bill? "); //Convert the input to an int. total = Integer.parseInt(inputString); // Calculate the tax amount. taxAmount = 6.75/100 * total; // Calculate the total meal after tax has been added. totalMeal = taxAmount + total //Calculate the tip tip = 15/100 * totalMeal // Calculate the entire bill. overall = totalMeal + tip; System.out.println("The taxed amount is" + taxAmount); System.out.println("The tip amount is" + tipAmount); System.out.println("The total bill is" + overall) System.exit(0); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.