Java Blog

 
 
 
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();
    }
    public void 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();
    }
    public void run()
    {
        for(int i=0;i<2;i++)
        {
            d.d_dispOrder(t);
        }
    }
}
class Restaurant
{
    public static void 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

*/

    Related Post:
  1. An applet program to display sum of two number of textField

  2. Program of storing and retrieving integers using data streams on a single file

  3. Program to read rollno, marks of sub1,sub2 and sub3 and on basis of that display result

  4. RMI program of count server and client

  5. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  6. Program to show an example of searching Strings for subStrings

  7. Program to declare, initialize and print a StringBuffer object

  8. Program to show some properties of StringBuffer object

  9. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  10. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  11. Program to show an example of overloading constructors in a class to initialize its data members

  12. Program to read the ballots and count the votes cast for each candidate using an array variable count

  13. Program to show an example of Multiple Levels of Inheritance

  14. Program of concatenating and Buffering files

  15. File handling program to copy bytes from one file to another

  16. Program to show an example of Concatination of Strings

  17. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  18. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  19. Program of an applet to display alternate filled and empty circle

  20. Program to display attributes of a specified file

 
 
Didn't find what you were looking for? Find more on Write a program for restaurant