In: Computer Science
Java program for food bill
There are N friends went to a restaurant and after having the meal, they want to divide the bill amount equally among them. Please write a java code to obtain the bill amount, the percentage of tax and number of people from the user. Your code should compute Total Bill amount, tax amount, and each person’s share. Where, Total bill amount= bill amount+ tax amount For example, if bill amount=100.00$ Percentage of taxes= 2 % and Number of people=4, then your code has to compute Total bill amount= 102.00 $, Tax amount= 2 $ and share of each person = 25.50 $
Your code should print Bill amount, tax amount, total bill amount, Number of people, and amount to be paid by each person. You may want to use double or floating-point data type for bill amount, tax percentage, and tax amount. To read floating data from keyboard, you may want to use statements as below. Scanner inp=new Scanner(System.in); billamount=inp.nextFloat();
// FoodBill.java : Java program to create a program for food bill that displays the share of each person
import java.util.Scanner;
public class FoodBill {
public static void main(String[] args) {
double bill_amount, tax_percent, tax, total_amount;
int num_people;
Scanner scan = new Scanner(System.in);
// input of bill amount
System.out.print("Enter the bill amount : ");
bill_amount = scan.nextDouble();
// input of tax as percentage
System.out.print("Enter the tax percentage : ");
tax_percent = scan.nextDouble();
// input of number of people
System.out.print("Enter the number of people : ");
num_people = scan.nextInt();
tax = (bill_amount*tax_percent)/100; // calculate the total tax on the bill
total_amount = bill_amount + tax; // calculate the total bill amount
// print the bill amount, tax, total bill amount, number of people and each person's share
System.out.printf("\nBill Amount : $%.2f",bill_amount);
System.out.printf("\nTax Amount : $%.2f",tax);
System.out.printf("\nTotal Bill Amount : $%.2f",total_amount);
System.out.printf("\nNumber of people : %d",num_people);
System.out.printf("\nAmount paid by each person : $%.2f",(total_amount/num_people));
scan.close();
}
}
//end of program
Output: