deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş Java Program to Calculate Restaurant Bill | Java Programs
Latest :

Java Program to Calculate Restaurant Bill | Java Programs

Java code to calcuate the resturant bill, the following program is pretty simple one along with sample outputs. We have choosen the famous south indian food to create the following program.

We all go to restaurants frequently and eat. Today, let us write a code to calculate the restaurant bill. With multiple items in a restaurant (in our case 10), our menu card with the items and its respective prices are already fixed.

So, two of our input arrays- items s (string) and rate (int) are already declared in the code along with their values. The only variable input is the quantity of these 10 items- qt array(int) that can be taken at runtime with the help of Scanner class in Java.

Since it is convenient to have the list displayed in front of us while placing each order, so we first print the items and their prices in our console screen with serial number, item and rate.

We have 10 choices (0-9) so, we make use of an integer variable (ch) and read the choice value between 0-9 with the use of Scanner class.

Based on the entered choice, the quantity (qt) at that particular choice is incremented by 1.

if(ch>0 && ch<10) {

System.out.println(“enter the no of quantites of “+s[ch-1]);

int q=input.nextInt();

qt[ch-1]+=q; }

If the choice entered is outside the given condition i.e., not in between the 10 values then, the a boolean variable (quit) is made false.

else { quit=false; }

These statements keep repeating until the boolean variable (quit) is made false indicating that the choice entered is outside range telling us that it marks the end of the order and we must exit.

After completion of order, we traverse through the quantity array (qt) till the end, and for every value of qt which is not equal to zero, we multiply the quantity and the rate of the particular item and add this to a variable(sum) which is used to find the entire bill.

for(int i=0;i<10;i++) {

if(qt[i]!=0) {

sum+=qt[i]*rate[i];

System.out.println(s[i]+”* “+qt[i]+”==”+qt[i]*rate[i]+”rs”); } }

We can display the total price of each item and then finally display our total bill (sum) in the console screen.

Java Code Resturant Bill

Output:

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş
x

Check Also

GCD Of Two Numbers In Java – Programs | 5 Ways

Java program to find out the GCD between two numbers. Here, we will discuss the ...