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....."); } } } }