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 in CORBA which takes a long sentence from the client (at least 7 words), passes to the server, server separates out each word

  2. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  3. RMI application for counting factorial of a given number.

  4. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  5. Program to declare and initialize Integer variables and print them on the Standard Output Device

  6. Program to show an example of creating a String object from a StringBuffer Object

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

  8. Program to show the use of Break Statement

  9. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  10. Program of telnet server - client

  11. Program to show an example of creating String objects from Character Arrays

  12. Socket program of HTTP Server

  13. Program of inventory management and demonstrating interactive input and output

  14. Program to convert the given temperature in faherenhiet to celsius using the following conversion formula C= F- 32/1.8

  15. Program of reading and writing primitive data

  16. Program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

  17. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  18. Program to show the use of Conditional AND Operator (&&) in If Statements

  19. Program that maintains employee database of an education system

  20. Program to show the use of Conditional OR Operator (||) in If Statements

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