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:

x

Check Also

Merge Sort Java – Program 2 Ways | Sortings

Merge Sort Java –  Java program to implement merge sort using array & Buffered reader. ...

grandpashabetgrandpashabetGrandpashabethttps://mobilebarhawaii.com/ballettea tropazhacklinkgrandpashabetatakoy escortatakoy escortGrandpashabetonwinligobetDeneme Bonusu veren sitelerYalova escortbakırköy escorthalkali escortGrandpashabetstarzbetkucukcekmece escortbağcılar escortjojobetsightcarefatih escorttekirdag Escortmaltepe escortdeneme bonusu veren sitelerzbahisescort kadıköyarnavutkoy escortstarzbetjojobethttps://canlicasino.shorthandstories.com/https://canlicasino.shorthandstories.com/basaksehir escortistanbul, escortjojobetholiganbetHoliganbet GirişHoliganbet Girişcasibom güncel girişBeylikdüzü escortextrabetholiganbet girişimajbetmavibetextrabetbetturkeybetwoongrandpashabetcasibombets10Grandpashabetonlyfans leakscratosroyalbetgrandpashabetmeritkingkingroyal telegramromabetromabetromabetlunabettürk pornoselcuksportshdtaraftariumtaraftariumbahiscombetexpercasibom girişolabahiscasibomtipobetkulisbetganobetGrandpashabetgrandpashabetdeneme bonusu veren kumar sitelericasibommarsbahisbelek escortafyon escortBetwoonholiganbet girişjojobetonwin girişcanlı casinodeneme bonusuligobetnakitbahisbetciovaycasinojojobetcanlı casinojokerbetcasibomganobet girişcasibomcasibomrekabet bahis girişhttps://www.newstrendline.com/selçuksportskumar sitelericasibomdeneme bonusu veren sitelernowinnowincratosroyalbetcratosroyalbetcasibom girişcasibom카지노사이트batumi escortscasibomonwincasibom girişhttps://sonbahisegiris.com/sonbahis-sikayet/holiganbetholiganbet girişcasibompusulabetmatbetcasibommadridbetjojobetextrabetjojobetjojobetdinamobetbetciomegabahiszbahisotobetbetturkeyonwin kayıtjojobetgrandpashabet