Results 1 to 3 of 3

Thread: Parameter help?

  1. #1
    glockner is offline Member
    Join Date
    Jan 2015
    Posts
    31
    Rep Power
    0

    Default Parameter help?

    I am creating a program to simulate a store. I have several methods listed below that imitate a customer arriving to the store, and a customer departing the store. I have a simulate method that simulates the entire store day. In my simulate() method under in the departure part, I cannot figure out how to call the number of the cashier for the parameter. I call the customerDeparts() method line 111, 112 and need two parameters, num of cashier, and currentTime. Any ideas on how to call the value of the cashier? Thanks.

    Java Code:
        /********************************************
         * Customer to cashier
         * @param number of cashier
         ********************************************/
        private void customerToCashier (int num){
    
            //Move first customer to cashier
            if(inLine.size() > 0){
                cashiers[num] = inLine.remove(0);
            }
    
            //Update customers served
            customersServed ++;
    
            //Update total wait time
            waitTime += currentTime - cashiers[num].getArrivalTime();
    
            //Future time for departure
            double futureTime = currentTime + futureEventTime(serviceTime);
    
            //Create new departure event + add to priority queue
            GVevent next = new GVevent(GVevent.DEPARTURE, futureTime, num);
            myEvents.add(next);
    
        }
    
        /********************************************
         * Customer Arrives
         * @param time of customer getting in line
         ********************************************/
        public void customerArrives (double t){
    
            //Update current time
            currentTime = t;
    
            //Create new customer, add to line
            Customer c = new Customer(t);
            inLine.add(c);
    
            //Check for if longest line
            if(inLine.size() > longestLine){
                longestLine = inLine.size();
                longestTime = currentTime;
            }
    
            //Move first customer in line to available cashier
            int i = cashierAvailable();
            if(i >= 0){
                customerToCashier(i); 
            }
    
            //Generate future time
            double n = futureEventTime(arrivalTime);
    
            //Check time to make sure not after closing, add to queue
            if(n < CLOSE){
                GVevent next = new GVevent(GVevent.ARRIVAL, t); 
                myEvents.add(next);
            }
        }
    
        /********************************************
         * Customer Departs
         * @param num of cashier available
         * @param time
         ********************************************/
        public void customerDeparts (int num, double t){
    
            //Update current time
            currentTime = t;
    
            //Retrieve customer from cashier[num]
            customerToCashier(num);
    
            //Check to see if cashier gets new customer
            if(inLine.size() > 0){
                cashiers[num] = inLine.remove(0);
            }else{
                cashiers[num] = null;
            }
    
        }
    
        /********************************************
         * Simulation of store
         ********************************************/
        public void simulate(){
    
            //Reset Parameter
            currentTime = OPEN;
            customersServed = 0;
            myEvents = new PriorityQueue <GVevent> ();
    
            //First Arrival
            GVevent a = new GVevent(GVevent.ARRIVAL, currentTime);
            myEvents.add(a);
    
            //Continue as long as there are events
            while(!myEvents.isEmpty()){
    
                //Get next event, update time
                a = myEvents.poll();
                currentTime = a.getTime();
    
                //Customer arrives
                if(a.isArrival()){
                    customerArrives(currentTime);
                }
                
                //Customer Departs
                if(a.isDeparture()){
                    customerDeparts(, currentTime);
                }
            }
            
            //Print Results
            calcResults();
        }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Parameter help?

    At some point I presume the customer is assigned a cashier. So that information needs to be saved so you can retrieve it. Once the customer is checked out the cashier becomes available.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Parameter help?

    Seems to me that this GVEvent class you have needs to know a little more; right now it only represents an event of "a" customer, but it does not know which specific customer.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. How to get the parameter from a JSP?
    By kosmos890 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-12-2014, 07:52 PM
  2. Not getting parameter in Servlet
    By handro1104 in forum NetBeans
    Replies: 3
    Last Post: 10-30-2013, 07:38 PM
  3. Output parameter
    By xdzgor in forum JDBC
    Replies: 4
    Last Post: 11-19-2010, 08:03 AM
  4. Using ArrayList as a parameter
    By Crypts in forum New To Java
    Replies: 6
    Last Post: 05-13-2010, 06:56 AM
  5. Subclass name to be a parameter?
    By Peetahzee in forum New To Java
    Replies: 6
    Last Post: 12-12-2009, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •