Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Networking TechnologyRSS Feeds

Write a program for restaurant

Posted By: Abby Fischer     Category: Java     Views: 10745

Write a program for restaurant. When customer place an order then and only then Manager can take the Order or generate a bill of an Order. Use Inter Thread Communication. And customerOrder the customer order After it place the Order. You have to customerOrder minimum three order of the customer.

Code for Write a program for restaurant in Java

import java.io.*;

class customerOrder
{
    boolean valueset=false;
    String str[]=new String[3];

    synchronized void d_takeOrder(Thread t)
    {
        if(valueset)
        {
            try
            {
                wait();        
            }catch(InterruptedException e)
            {
                System.out.println(e);
            }
        }
        System.out.println("\n"+t);
        try
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            for(int i=0;i<3;i++)
            {
                System.out.print("\n Take an Order "+(i+1)+" :: ");
                str[i]=br.readLine();
            }
        }catch(IOException e)
        {
            System.out.println(e);
        }

        valueset=true;
        notify();
    }
    synchronized void d_dispOrder(Thread t)
    {
        if(!valueset)
        {
            try
            {
                wait();        
            }catch(InterruptedException e)
            {
                System.out.println(e);
            }
        }
        System.out.println("\n"+t);
        for(int i=0;i<3;i++)
        {
            System.out.print("\n Place an Order "+(i+1)+" :: "+str[i]);
        }
        valueset=false;
        notify();
    }
    
}
class takeOrder implements Runnable
{
    customerOrder d;
    Thread t;
    takeOrder(customerOrder d)
    {
        this.d=d;
        t=new Thread(this,"Manager take an order");
        t.start();
    }
    publicvoid run()
    {
        for(int i=0;i<2;i++)
        {
            d.d_takeOrder(t);
        }
    }
}
class dispOrder implements Runnable
{
    customerOrder d;
    Thread t;
    dispOrder(customerOrder d)
    {
        this.d=d;
        t=new Thread(this,"Manager place an order");
        t.start();
    }
    publicvoid run()
    {
        for(int i=0;i<2;i++)
        {
            d.d_dispOrder(t);
        }
    }
}
class Restaurant
{
    publicstaticvoid main(String args[])
    {
        customerOrder d=new customerOrder();
        new takeOrder(d);
        new dispOrder(d);
    }
}
/*
Output

Thread[Manager take an order,5,main]

Take an Order 1 :: 2 Roti

Take an Order 2 :: 1 plat Veg.Jaipuri Sabji

Take an Order 3 :: 1 plat Pulav

Thread[Manager place an order,5,main]

Place an Order 1 :: 2 Roti
Place an Order 2 :: 1 plat Veg.Jaipuri Sabji
Place an Order 3 :: 1 plat Pulav

Thread[Manager take an order,5,main]

Take an Order 1 :: 3 Roti

Take an Order 2 :: 1 plat Paneerkadai Sabji

Take an Order 3 :: 1 plat Biriyani

Thread[Manager place an order,5,main]

Place an Order 1 :: 3 Roti
Place an Order 2 :: 1 plat Paneerkadai Sabji
Place an Order 3 :: 1 plat Biriyani

*/
  
Share: 


Didn't find what you were looking for? Find more on Write a program for restaurant Or get search suggestion and latest updates.

Abby Fischer
Abby Fischer author of Write a program for restaurant is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!