Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners fast food restaurant
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Alyssa
fast food restaurant
0 Answer(s)      3 years and 5 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.....");
            }
        }
        }
}

Advertisement
View Answers

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
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
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
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
What is Hospitality Management?
restaurant management, food and beverage operations, food preparation, food..., culinary facilities, restaurants, cafes,food joints, retreats, resorts, etc... depend upon the personality traits of the person, ability to fast learning
Hibernate Quickly
Hibernate Quickly In this fast changing programming world, each day new technologies are coming fast. These days there is very high demand of programmers knowing Hibernate. So, programmers wants to learn Hibernate Quickly
Boutique Hotels in Delhi
needs and comforts. The concept of boutique hotels in New Delhi is fast.... From food to room amenities everything is at par with global standards. What
About Dilli Haat of Delhi
Dilli Haat in Delhi The Dilli Haat is a large market and food court in Delhi. It is in Kidwai Nagar, a spot in the central part of the city that is south.... The Dilli Haat Market of Delhi is also home to a large food court. This court
Jadclipse
Jadclipse       JadClipse is a plug-in that seamlessly integrates Jad (the fast Java decompiler) with Eclipse. Normally, when opening a class file the Class File
MOR
MOR       It is an open source advanced FAST billing solution used for Asterisk PBX. The features of MOR are: Realtime! MySQL PayPal integrated Balance tracking Least Cost Routing with Fail
Open Source RFID
Open Source RFID RFID RFID systems can be used just about anywhere, from clothing tags to missiles to pet tags to food -- anywhere that a unique identification system is needed. The tag can carry information as simple as a pet
Java Server Pages(JSP)
a simplified, fast way to create dynamic web content. It is a server side scripting..., which are secure, fast, and independent of server platforms. It also allows
Struts-Layout
Struts-Layout       Struts-Layout is a tag library for Apache Struts which provides easy and fast interface creation. This is achieved by powerful tags which display panels, input fields
What is MySQL
; MySQL is a open source Relational Database Management System. MySQL is very fast... MySQL are very fast and much reliable for any type of application. MySQL... while server is running. MySQL has a wide user base. It is a very fast
Sales Marketing Job
Sales Marketing Job       Position Vacant: Business Development Executives Company Name: Parisonz Technologies Pvt Ltd Company Profile: Parisonz is a fast growing Singapore
Open Source POS
Open Source POS Open-source POS system This past weekend People's Food Co-op in SE Portland made history. During a conference with tech and IT folk... This past weekend People's Food Co-op in Portland, Cascadia made history. During
Fleet truck tracking
As the fleet business involving trucks is growing fast, fleet truck tracking has become all the more important for fleet owners. Truck is the most used vehicle to carry goods and items to far off places and most of the time they travel
Java Training at Noida
at very fast rate in Noida- one of the emerging IT Business hubs in India. Now you
Advertisements
 

 

 

DMCA.com