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. Program to find a factorial of a given number

  2. Program to show the use of Logical OR Operator (|) in If Statements

  3. Program to display attributes of a specified file

  4. Program to display triangle of numbers

  5. Program to determine the sum of the following harmonic series for a given value of n

  6. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  7. Program to Display Output in triangular shape

  8. Program to change characters in a StringBuffer objects and to reverse its contents

  9. Program to show an example of using a Static Nested Class outside the Top-Level Class

  10. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

  11. Program in CORBA which takes a long sentence from the client (at least 7 words), passes to the server, server separates out each word

  12. RMI application for getting the final total price of the shopping list with some of the following items and quantities chosen by the user

  13. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  14. Socket program of multi client chat server

  15. Program of binary search tree

  16. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  17. Program to read bytes from a file

  18. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  19. Write a program for restaurant

  20. Corba program of reverse string

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