-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantBill.java
More file actions
45 lines (35 loc) · 1.51 KB
/
RestaurantBill.java
File metadata and controls
45 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//RestaurantBill.java
import java.util.Scanner; //Needed for the Scanner class
/**
This program calculates tip and tax of a restaurant meal.
*/
public class RestaurantBill
{
public static void main(String[] args)
{
double taxPercent = 0.0625; //Sales tax percentage
double tax; //The calucated tax
double tipPercent = 0.2; //Tip percentage
double tip; //The calculated tip
double mealCharge; //Cost of the meal
double mealChargeWithTax; //Cost of the meal with tax
double mealChargeWithTaxAndTip; //Cost of the meal with tax and tip
//Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
//Get the cost of the meal
System.out.print("What was the total cost of the meal before tax? ");
mealCharge = keyboard.nextDouble();
//Calculate the tax and the total with tax (but without tip)
tax = (mealCharge * taxPercent);
mealChargeWithTax = (tax + mealCharge);
//Calculate the tip
tip = (mealChargeWithTax * tipPercent);
//Calculate the total for the meal with tax and tip
mealChargeWithTaxAndTip = (mealChargeWithTax + tip);
//Display the resulting information.
System.out.println("\tMeal Charge: $" + mealCharge);
System.out.println("\tTax: $" + tax);
System.out.println("\tTip: $" + tip);
System.out.println("\tTotal: $" + mealChargeWithTaxAndTip);
}
}