Friday, September 30, 2011

BlueJ Program On Producing Bill In Restaurant


In this program the items available in a restaurant along with rates will be displayed. A customer has to choose atleast 2 items from the menu card. The customer will get option to cancell items from his order but the number of items in his order will be always at least two. At the end of the program bill will be produced.

2017 ISC Computer Application Paper Suggestion: CLICK HERE

  import java.io.*;
class Bill
{
 String item[]={"A","B","C","D","E","F","G","H","I","J"};
 double rate[]={1,2,3,4,5,6,7,8,9,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("East West 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++;
         if(x>1)
         {
             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< 2)
         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-1;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("*******************");
          bamt=bamt+bamt*.125;
          System.out.println("Total Amount including service charge @ 12.5% Rs.                   "+bamt);
          
}
}

You May Like It: Computer Teacher at Burdwan

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


Related PostBlueJ Projects For ICSE Students

10 comments:

  1. Can you please post the variable description ?

    ReplyDelete
  2. Can you show me the main method call of this?

    ReplyDelete
    Replies
    1. public static void main(String args[]) throws Exception
      {
      Bill ob=new Bill();
      ob.putOrder();
      }

      Copy and paste the above codes in the above program before the last closing brace as shown below:


      bamt=bamt+bamt*.125;
      System.out.println("Total Amount including service charge @ 12.5% Rs. "+bamt);

      }

      public static void main(String args[]) throws Exception
      {
      Bill ob=new Bill();
      ob.putOrder();
      }

      }

      Delete
  3. Can we link a method from another method during runtime i.e
    once we create an object we open an instance and after the terminal window displays result, in the terminal window itself can use some code to link it to another method and its result
    say
    i complie a program to make a bill and i have taken two mehtods 1.to show the options available and to allow the user to chose his requirements and 2.to display the amount he must pay and other details of a bill (with another method in between to do the calculation which is private).
    can i have link that can let the user connect with the display method without going back to the instance??

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner