Last active
April 20, 2022 02:51
-
-
Save ellenia/0edb5f6372f94dd629c531823474cd8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Write a program that computes the tax ad tip on a restaurant bill | |
* The program should ask the user to enter the charge for the meal. | |
* The tax should be 6.75 percent of the meal charge. The tip | |
* should be 15 percent of the total after adding the tax. Display | |
* the meal charge, tax amount, and the total bill on the screen. | |
*/ | |
import java.util.Scanner; | |
public class RestaurantBill1 | |
{ | |
public static void main(String[] args) | |
{ | |
double mealCharge; | |
final double tax = 0.0675; // 6.75% constant amount of meal charge | |
double taxAmount; | |
double totalWithTax; | |
final double tip = 0.20; // 20% constant amount of total amount after adding tax amount | |
double tipAmount; | |
double totalBill; | |
Scanner keyboard = new Scanner(System.in); | |
//user has to enter the charge for the meal | |
System.out.print("Please enter the charge for your meal $"); | |
mealCharge = keyboard.nextDouble(); | |
keyboard.nextLine(); | |
//calculate meal charge, tax amount, tip amount, and total bill | |
taxAmount = mealCharge * tax; | |
totalWithTax = mealCharge + taxAmount; | |
tipAmount = totalWithTax * tip; | |
totalBill = totalWithTax + tipAmount; | |
//display to user meal charge, tax amount, tip amount, and total bill | |
System.out.println("Your meal charge amount is $" + mealCharge + "."); | |
System.out.println("Your tax amount is $" + taxAmount + "."); | |
System.out.println("Your tip amount is $" + tipAmount + "."); | |
System.out.println("-----------------------------------"); | |
System.out.println("Your total bill amount is $" + totalBill + "."); | |
//end the program | |
System.exit(0); | |
} | |
} | |
import javax.swing.JOptionPane; | |
public class RestaurantBill2 | |
{ | |
public static void main(String[] args) | |
{ | |
String input; | |
String bill; | |
double mealCharge; | |
final double tax = 0.0675; // 6.75% constant amount of meal charge | |
double taxAmount; | |
double totalWithTax; | |
final double tip = 0.20; // 20% constant amount of total amount after adding tax amount | |
double tipAmount; | |
double totalBill; | |
//user has to enter the charge for the meal | |
input = JOptionPane.showInputDialog("Please enter the charge for your meal $"); | |
mealCharge = Double.parseDouble(input); | |
//calculate meal charge, tax amount, tip amount, and total bill | |
taxAmount = mealCharge * tax; | |
totalWithTax = mealCharge + taxAmount; | |
tipAmount = totalWithTax * tip; | |
totalBill = totalWithTax + tipAmount; | |
//display to user meal charge, tax amount, tip amount, and total bill | |
bill = "Your meal charge amount is $" + mealCharge + "." + "\n" + | |
"Your tax amount is $" + taxAmount + "." + "\n" + | |
"Your tip amount is $" + tipAmount + "." + "\n" + | |
"-----------------------------------" + "\n" + | |
"Your total bill amount is $" + totalBill + "."; | |
JOptionPane.showMessageDialog(null, bill); | |
//end the program | |
System.exit(0); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello can ı contact with you can you help me please ? abdullaerdogan@hotmail.com