fast food restaurant

Ads

 
 

Share on Google+Share on Google+

Alyssa
fast food restaurant
0 Answer(s)      6 years and 6 months ago
Posted in : Java Beginners

I need to design a Java application to manage a drive-thru restaurant. There are two drive-thru windows to serve customers and a kitchen to prepare the ordered food. Use an random number generator to determine when a customer arrives. Assign the arrived customer to an available drive-thru window. If both widows are busy, put the customer in a waiting line.

Each customer may order any food from a menu that includes hamburgers, fries, drinks and cookies. The customer's order determines the time the kitchen takes to get the food ready. For example, hamburgers and fries may take longer than drinks and cookies. And, if the customer orders more of each, it will take longer too.

The program must display in each time unit the following information:

* Customers in the waiting line and/or new arrival
* The order being prepared and/or the order ready for each window

this is what i have so far:

import java.util.Random;
public class MainClass
{
    public static void main (String [ ] args)
    {
        Random gen = new Random ( );
        int capacity = 20;       //max # of customers in the waiting line
        Customer [ ] waitingLine = new Customer [capacity]; ;
        int  size = 0;          //actual # of customers in waiting
        DriveThruWindow window1 = new DriveThruWindow ();
        DriveThruWindow window2 = new DriveThruWindow ();
        Customer newArrival;
        while (true)
        {
            int whatHappens = gen.nextInt (100);
            if (whatHappens % 10  == 0)
            {
                newArrival = new Customer ();
                waitingLine[size++] = newArrival;
            }
            else  if (whatHappens == 0)
            {
               // closeTheRestaurant ( );
                break;
            }
            window1.update ();
            window2.update ();
            if (window1.isAvailable ( ))
            {
                if (size != 0)
                {
                    window1.startServingACustomer (waitingLine[0]);
                    for (int i = 0; i < size-1; i++)
                        waitingLine[i] = waitingLine[i+1];
                    size--;
                }
            }
            if (window2.isAvailable ( ))
            {
                if (size != 0)
                {
                    window2.startServingACustomer (waitingLine[0]);
                    for (int i = 0; i < size-1; i++)
                        waitingLine[i] = waitingLine[i+1];
                    size--;
                }
            }
            System.out.println ("\n\n**** customers waiting to place order......\n");
            for (int i = 0; i < size; i++)
                System.out.println (waitingLine[i].getTag ( ));
        }
        System.exit (0);
    }
}

public class Order
{
    private int orderNum;   //optional, not used now
    private Item [ ] items;
    private int numOfItems;
    private double total;
    private int totalTimeNeeded;


    public Order ( )
    {
        orderNum = 0;
        numOfItems = 0;
        total = 0;
        items = new Item [4];
        for (int i = 0; i < 4; i++)
            items[i] = new Item ( );
        totalTimeNeeded = 0;
    }

    public String toString ( )
    {
        String outString = "\n\n** order **";
        for (int i = 0; i < numOfItems; i++)
            outString += items[i];
        return outString;
    }

    public void setAnItem (String newName, double newUnitPrice,
            int newTimePerUnit, int newNum)
    {
        items[numOfItems].setItem(newName, newUnitPrice, newTimePerUnit,  newNum);
        total += items[numOfItems].getSubTotal( );
        totalTimeNeeded += items[numOfItems].getTimeNeeded ();
        numOfItems++;
    }


    public int getTotalTimeNeeded ( )
    {
        return totalTimeNeeded;
    }
}

public class Item
{
    private String name;
    private double unitPrice;
    private int timePerUnit;
    private int num;
    private double subTotal;
    private int timeNeeded;

    public Item ( )
    {
        name = "";
        unitPrice = 0;
        num = 0;
        subTotal = 0;
        timePerUnit = 0;
        timeNeeded = 0;
    }
    public Item (String newName, double newUnitPrice,
            int newTimePerUnit, int newNum)
    {
        name = newName;
        unitPrice = newUnitPrice;
        num = newNum;
        subTotal = unitPrice * num;
        timePerUnit = newTimePerUnit;
        timeNeeded = timePerUnit * num;
    }
    public void setItem (String newName, double newUnitPrice,
            int newTimePerUnit, int newNum)
    {
        name = newName;
        unitPrice = newUnitPrice;
        num = newNum;
        subTotal = unitPrice * num;
        timePerUnit = newTimePerUnit;
        timeNeeded = timePerUnit * num;
    }
    public String toString ( )
    {
        return "\n\nitem name: " + name + "\nnum of units: " +
                num + "\nunit price: " + unitPrice + "\nsubtotal: " +
                subTotal;
    }
    public double getSubTotal ( )
    {
        return subTotal;
    }
    public int getTimeNeeded ( )
    {
        return timeNeeded;
    }
}

import java.util.Random;
import java.util.Scanner;
public class Customer
{
    private String tag;
    private Order food;
    private int totalTime;

    public Customer ( )
    {
        setTag ();
        food = new Order ();
        totalTime = 0;
    }
    private void setTag ( )
    {   //4 upper case letters
        Random gen = new Random ();
        tag = "";
        for (int i = 0; i < 4; i++)
        {
            int code = gen.nextInt (26)+ 65;
            tag += (char) code;
        }
     }

     public void placeOrder (double dPrice, double fPrice, double hPrice, double cPrice,
                int dTime, int fTime, int hTime, int cTime)
    {
        Scanner inputDevice = new Scanner (System.in);
        System.out.println ("\n\ncustomer " + tag + ", please place your order......");

        for (int  i = 0; i < 4; i++)
        {
            System.out.print ("\n\n1: drinks: " + dPrice + "\n" +
                     "2: fries: " + fPrice + "\n" +
                     "3: hamburgers: " + hPrice + "\n" +
                     "4: cookies: " + cPrice + "\n" +
                     "Enter your choice. " + "\n" +
                                         "To end the order, enter 0: ");
            int foodChoice = inputDevice.nextInt ( );
            String foodName = "";
            double unitPrice = 0;
            int howMany = 0;
            int timePerUnit = 0;
            if (foodChoice == 0)
                break;
            else if (foodChoice == 1)
            {
                foodName = "drinks";
                unitPrice = dPrice;
                timePerUnit = dTime;
            }
            else if (foodChoice == 2)
            {
                foodName = "fries";
                unitPrice = fPrice;
                timePerUnit = fTime;

            }
            else if (foodChoice == 3)
            {
                foodName = "hamburgers";
                unitPrice = hPrice;
                timePerUnit = hTime;

            }
            else if (foodChoice == 4)
            {
                foodName = "cookies";
                unitPrice = cPrice;
                timePerUnit = cTime;

            }

            System.out.print ("how many: ");
            howMany = inputDevice.nextInt ( );
            food.setAnItem (foodName, unitPrice, timePerUnit, howMany);
        }

        System.out.println ("\n\ncustomer " + tag + " this is what you just ordered.....");
        System.out.println (food);
        totalTime = food.getTotalTimeNeeded ( );
        System.out.println ("your waiting time is " + totalTime);
    }
    public int getTotalTime ( )
    {
        return totalTime;
    }
    public String getTag ( )
    {
        return tag;
    }
}

public class DriveThruWindow
{
    private Customer whoIsBeingServed;
    private boolean available;

    private int clock;

    private final double DRINKS_PRICE = 1.5;
    private final double FRIES_PRICE = 1.7;
    private final double HAMBURGERS_PRICE = 2.5;
    private final double COOKIES_PRICE = 0.25;

    private final int DRINKS_TIME = 1;
    private final int FRIES_TIME = 2;
    private final int HAMBURGERS_TIME = 3;
    private final int COOKIES_TIME = 1;

        private double totalTime;
        private double placeOrder;
        private double output;
        private int timeLeftToFinish;
        private String tag;
    private Order food;


        public DriveThruWindow ( )
        {
            whoIsBeingServed = null;
            available = true;
            clock = 0;
        }

        public void startServingACustomer (Customer newCustomer)
        {
            whoIsBeingServed = newCustomer;
            System.out.println("welcome to Alyssa's fast food restaurant");
            totalTime = whoIsBeingServed.getTotalTime();
            //food = whoIsBeingServed.getOrder();
            //gasType = whoIsBeingServed.getGasType();
            //gasPurchased = whoIsBeingServed.getGasPurchased();
            //timeLeftToFinish = (int) (gasPurchased / HOSE_FLOW_RATE);
            System.out.println(timeLeftToFinish
                + " units of time needed for this transaction...");
            //Tag = whoIsBeingServed.getTag();
            available = false;
            whoIsBeingServed.placeOrder (DRINKS_PRICE, FRIES_PRICE,
                            HAMBURGERS_PRICE, COOKIES_PRICE,
                        DRINKS_TIME, FRIES_TIME,
                            HAMBURGERS_TIME, COOKIES_TIME);
            clock = whoIsBeingServed.getTotalTime ( );
        }

        public boolean isAvailable ( )
        {
            return available;
        }

        public void update ( )
        {
        if (clock != 0)
        {
            clock --;
            if (clock == 0)
            {
            available = true;
            System.out.println ("\n\ncustomer " + whoIsBeingServed.getTag ( ) +
                                           ", your order is ready. thank you");
            System.out.println ("\nnext customer.....");
            }
        }
        }
}
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
fast food restaurant
fast food restaurant  I need to design a Java application to manage a drive-thru restaurant. There are two drive-thru windows to serve customers and a kitchen to prepare the ordered food. Use an random number generator
system ordering food
restaurant order service using java.The system read from a file containing...) from the particular restaurant. The system then alerts the restaurant. Eventually,the restaurant prepares the ordered menu and delivers them to the customer
Advertisements
Cafe and Restaurant Website Design
Cafe and Restaurant Website Design We provide high quality Cafe and restaurant... and restaurant business. We are designing, developing, testing, uploading and maintaining websites for cafe and restaurant industry. A website is the virtual
Restaurant Search Applications ? Find New Places To Eat, Fast!
Restaurant Search Applications – Find New Places To Eat, Fast! Mobile... out at great places and are always up for trying something new then restaurant... of restaurants In days gone by, when you wanted to find a restaurant you would have had
Hire an iPhone Developer to develop restaurant application
Hire an iPhone Developer to develop restaurant application  Hi, My client is running a restaurant. Client is looking for developing an iPhone application. I want to hire an iPhone Developer to develop restaurant application
Information about Fun N Food Village Delhi
Fun N Food Village of Delhi The Fun N Food Village is an amusement park... the park. The Fun N Food Village was opened in 1993. It was built as a theme park... and the enjoyable Bumper Boat ride. The Fun N Food Village is especially known
fast Reply - Java Beginners
fast Reply  Hi Friend I want to passing value one page to another page without using session varible....please help me write the code and send me   Hi friend, For solving the problem visit to : http
fast view web--yes - Struts
fast view web--yes  How to enable the fast web view--yes on pdf file  Hi Friend, Please clarify your problem. Thanks
Thanks for fast reply - Java Beginners
Thanks for fast reply  Thanks for response I am already use html for data grid but i m noot understood how to connect to the data base, and how to fetch data from table in the data grid I am using mysql database package
goto statement problem. reply fast.
goto statement problem. reply fast.  I have done some operation, and want to repeat same operation again at users choice. but its not working properly. I am using goto statement. void main() { float rs, p; char z
Version of cn.danielw>fast-object-pool dependency
List of Version of cn.danielw>fast-object-pool dependency
Version of com.landoop>fast-avro-write dependency
List of Version of com.landoop>fast-avro-write dependency
Version of ch.simschla>fast-and-simple-minify dependency
List of Version of ch.simschla>fast-and-simple-minify dependency
Version of com.btoddb>fast-persistent-queue dependency
List of Version of com.btoddb>fast-persistent-queue dependency
Version of com.e-gineering>collectd-fast-jmx dependency
List of Version of com.e-gineering>collectd-fast-jmx dependency
UMLet - Fast UML Editor
UMLet - Fast UML Editor       UMLet is an open-source UML tool with a simple user interface: draw UML diagrams fast, export diagrams to eps, pdf, jpg, svg
Maven Dependency fast-persistent-queue >> 0.0.13
You should include the dependency code given in this page to add Maven Dependency of com.btoddb >> fast-persistent-queue version0.0.13 in your project
Maven Dependency fast-and-simple-minify >> 1.0
You should include the dependency code given in this page to add Maven Dependency of ch.simschla >> fast-and-simple-minify version1.0 in your project
Maven Dependency fast-object-pool >> 2.0.0
You should include the dependency code given in this page to add Maven Dependency of cn.danielw >> fast-object-pool version2.0.0 in your project
Maven Dependency fast-persistent-queue >> 0.0.12
You should include the dependency code given in this page to add Maven Dependency of com.btoddb >> fast-persistent-queue version0.0.12 in your project
Maven Dependency fast-persistent-queue >> 0.0.14
You should include the dependency code given in this page to add Maven Dependency of com.btoddb >> fast-persistent-queue version0.0.14 in your project
Maven Dependency fast-persistent-queue >> 0.0.7
You should include the dependency code given in this page to add Maven Dependency of com.btoddb >> fast-persistent-queue version0.0.7 in your project
Maven Dependency fast-avro-write >> 0.1
You should include the dependency code given in this page to add Maven Dependency of com.landoop >> fast-avro-write version0.1 in your project
Maven Dependency collectd-fast-jmx >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.e-gineering >> collectd-fast-jmx version1.0.0 in your project
plz help me any one as fast as u can
plz help me any one as fast as u can  A thief Muthhooswamy planned to escape from **** jail. Muthhooswamy is basically a monkey man and he is able to jump across the wall. He practiced to cross a wall and he is able to jump 'X
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import
please reply fast if anyone knows that how to install mysql on windows using msi package
please reply fast if anyone knows that how to install mysql on windows using msi package  please reply fast if anyone knows that how to install mysql on windows using msi package   Hello Friend, visit here Thanks
How to execute my query fast..When A date filter is there in a query it takes more time for execution.?
How to execute my query fast..When A date filter is there in a query it takes more time for execution.?  When A date filter is there in a query... fast... please help
Cuisines of Delhi
restaurant for those who want to savor Indian and continental food in a hygienic...Cuisines of Delhi Delhi is also known as food lovers’ paradise as it has a great culture of food. The aroma of the various recipes make the air

Ads

 
Advertisement null

Ads