Customer Queue | 2008-09-28

Portfolio » Application Programming

This project is create to simulate the customer service queue where there require arrrival time, customer number and expected service during, there are two class files. Main.java where establish the queue abstract data type in LinkedList and Customer.java where is the object holds all the customer information.

 

Main.java

/*******************************************
Written by [email protected]
********************************************/

package CustomerQueue;
import java.util.Queue;
import java.util.LinkedList;

/**
 * @description:
 * This class file create the object of the customer information
 * @author Andy Ng
 */
public class Main {

    /**
     * @description:
     * This is the main method
     */
     public static void main(String[] args)
    {
        // Create customer instance
        Customer C = new Customer();

        // Create Queue impliment LinkedList
        Queue<String> Q=new LinkedList<String>();

        // Store     
        for( int i=0; i<C.getTotalCustomers(C.CustomerArry); i++)
           Q.add(Integer.toString(i));  // i as Customer unique number

        // Display during removing, print out all customer info by customer id number
        while(!Q.isEmpty())
        {
          System.out.print( "Time: "+C.getArrivalTime( C.CustomerArry, Integer.valueOf(Q.element()) ) + " | " );

          // String manipulate to give proper format of "st", "nd" or "th"
          if(Q.element().substring(Q.element().length()-1,Q.element().length()).equals("0")) // Shift 1; 1st
              System.out.print( C.getCustomerNumber( C.CustomerArry, Integer.valueOf(Q.element()) ) + "st customer enters | "  );
          else if(Q.element().substring(Q.element().length()-1,Q.element().length()).equals("1")) // Shift 1, 2nd
              System.out.print( C.getCustomerNumber( C.CustomerArry, Integer.valueOf(Q.element()) ) + "nd customer enters | "  );
          else
              System.out.print( C.getCustomerNumber( C.CustomerArry, Integer.valueOf(Q.element()) ) + "th customer enters | "  );

          System.out.print( "Serive duration expected: "+C.getServiceDuration( C.CustomerArry, Integer.valueOf(Q.element()) ) + " | "  );
          System.out.println( "Total "+Q.size()+" Customer in Queue");
          Q.remove(); // remove top
        }
    } // main
} // class

 

 Customer.java

 /*******************************************
Andy by [email protected]
********************************************/

package CustomerQueue;

/**
 * @description:
 * This class file create the object of the customer information
 * @author Andy Ng
 */
public class Customer {

  // Customer information
  private String CustomerIdNumber;  // The unique number of the customer
  private String ArrivalTime;       // The time the customer arrive
  private String ServiceDuration;   // Expexcte how long it will take
  ***


  // Construct
  public void Customer( int ArrivalTime ){}
  // Create Customer data in two dimension array
  // Format: { Customer number, Arrival time, Expected service duration }
  String[][] CustomerArry = {
      {"1","9:05","40"},
      {"2","9:30","35"},
      {"3","9:45","45"},
      {"4","10:20","30"},
      {"5","10:30","40"},
      {"6","10:50","15"},
  }; // CustomerArry

/**@description: Get total customer in size
 * @param  String[][] CustomerArry
 * Customer data
 * @return int CustomerArry.length
 * Customer data array length
 */
  public int getTotalCustomers( String[][] CustomerArry )
  {
      return CustomerArry.***;
  }

/**
 * @description: Get Customer Number by Customer Id Number
 * @param  String[][] CustomerArry
 * Customer data
 * @return int CustomerNumbe
 * Unique ordered Customer Id Number
 */
  public String getCustomerNumber( String[][] CustomerArry, int CustomerNumber )
  {
      CustomerIdNumber = CustomerArry[CustomerNumber][0];
      ***
      return CustomerIdNumber;
  }

/**
 * @description: Get Customer arrival time by Customer Id Number
 * @param  String[][] CustomerArry
 * Customer data
 * @return int CustomerNumbe
 * Unique ordered Customer Id Number
 */
***
***
***


/**
 * @description: Get Customer service duration time by Customer Id Number
 * @param  String[][] CustomerArry
 * Customer data
 * @return int CustomerNumbe
 * Unique ordered Customer Id Number
 */
  public String getServiceDuration( String[][] CustomerArry, int CustomerNumber )
  {
      ServiceDuration = CustomerArry[CustomerNumber][2];
      return ServiceDuration;
  }
}
 

*** indicated that some partial codes has been removed