Sunday, July 29, 2018

Restaurant Bill Producing BlueJ Program with Discount


  import java.io.*;
class Bill
{
 String item[]={"Pasta","Cheese Pizza","Mini Burgers with Cheeze","Corn Dogs","Grilled Chicken","Chrispy Popcorn","Tempura Green Beans","Double Decker Chicken","Pav Bhaji","Samosa"};
 double rate[]={100,102,103,104,105,106,107,108,50,10};
 String order[]=new String[10];
 double amt[]=new double[10];
 String ans;
 int plates[]=new int[10];
 int i,n=0,no,x=0;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 Bill()
 {
 
 }

 public void putOrder()throws IOException
 {
     System.out.println("**********************************************");
      System.out.println("St. Paul's Student's Canteen - MENU CARD");
      System.out.println("*********************************************");
      System.out.println("Item No.         Item            Rate/plate");
      for(i=0;i< 10;i++)
      {
                System.out.println((i+1)+ ":                "+item[i]+"------------------"+rate[i]);
      }
            System.out.println("You have to order at least 2 items. Enter item number to place order\n");
       
     while(true)
     {
          if(x==10)
          break;
         System.out.println("Enter item number:");
         no=Integer.parseInt(br.readLine());
         order[x]=item[no-1];
         amt[x]=rate[no-1];
         System.out.println("How many plates?:");
         no=Integer.parseInt(br.readLine());
         plates[x]=no;
         x++;
           System.out.println("Any More Item ?(Y/N):");
        ans=br.readLine().toUpperCase();
             if(ans.equals("N"))
             break;
 }
 showBill();

}
private void showBill() throws IOException
{
double bamt=0,b;
  System.out.println("You have ordered\n");
   System.out.println("Item       Rate         No. of Plates");
  for(i=0;i< x;i++)
  {
       System.out.println((i+1)+":"+order[i]+"---"+amt[i]+"---"+plates[i]);
    }
    while(true)
    {
         if(x<=1)
         break;
         System.out.println("Want to cancell any item (Y/N):");
         ans=br.readLine().toUpperCase();
         if(ans.equals("N"))
         break;
         System.out.println("Which item to cancell, enter item number:");
         no=Integer.parseInt(br.readLine());
         for(i=no-1;i< x;i++)
         {
              order[i]=order[i+1];
              amt[i]=amt[i+1];
              plates[i]=plates[i+1];
            }
            x--;
        }
        System.out.println("Cash Memo\n");
        System.out.println("*****************************************************************");
        System.out.println("Item          No. of plates      Rate           Amount\n");
         System.out.println("***************************************************************");
         for (i=0;i< x;i++)
         {
               System.out.print(order[i]+ "             "+plates[i]+ "              "+ amt[i]+ "                      ");
     
        b=plates[i]*amt[i];
         System.out.println(b);
         bamt=bamt+b;
        }
         System.out.println("Bill Amount Rs.                                     "+bamt);
          System.out.println("*******************");
          if (bamt>=500)
          bamt=bamt-bamt*.125;
          System.out.println("Total Amount after discount @ 12.5% Rs.(if applicable)                   "+bamt);
       
}
public static void main(String args[]) throws Exception
{
Bill ob=new Bill();
 ob.putOrder();
}
}


Variable description of the program




String item[] holds the items in the menu
double rate[] holds the rate of the items of menu card
String order[] it holds the items ordered by any customer
double amt[] it holds the price of items ordered
String ans It takes the choice of customer whether any more order is to be taken
int plates[] it holds the number of plates of each items ordered by customer
int x customer has to order atleast two items, ‘x’ keeps track of the number of items ordered.
int no items are ordered using the item number. ‘no’ holds the item number.
int i loop control variable.
double bamt holds the total bill amount
BufferedReader br It is used to take user input



No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner