The simulation of the system of the number dispatching in bank business

Source: Internet
Author: User

Demand:

1, the Bank has 6 service windows: 4 Ordinary Customer window, 1 VIP Customer window, a quick window

2, 3 kinds of customers: ordinary customers, VIP Customer window, quick window

3,

Simulate this business first:

The service window starts with a queue

4 Ordinary client Windows Start service;

1 VIP client window to start service;

1 quick Windows Start service;

The customer comes in to transact the business to obtain the number

The ordinary customer takes the number waiting to be called,

VIP customer number waiting to be called,

Fast customer pickup number waiting to be called,

From this understanding to the service personnel is through their respective windows to the number manager to the corresponding number, the customer is to select the corresponding number generator to wait to be called.

Now we abstract the Business Data: Service window (different window to different pick number), the service window includes the Banking service window and the Customer Fetch number window; The number manager is required for the number, and the customer and service personnel are required to number the different number managers, and there is a need for a class to manage the various number managers. There are 3 types of customers.

We design these classes separately.

1, the service window design (including 2 kinds)

For bank service personnel:

public class Serverwindow implements runnable{
Private CustomerType type;
private int windownum;
public void SetType (CustomerType type) {
This.type = type;
}
public void Setwindownum (int windownum) {
This.windownum = Windownum;
}
@Override
public void Run () {
while (true) {
Switch (type) {
Case COMMON:
Commonservice ();
Break
Case EXPRESS:
Expressservice ();
Break
Case VIP:
Vipservice ();
Break
}
}
}

/**
* Normal window
*/
private void Commonservice () {
String windowname = "First" + Windownum + "number" + Type + "window";
Integer servernum = Nummachine.getinstance (). Getcommmanager (). Serverwindowfetchnum ();
if (servernum!= null) {
int maxservertime = Constants.max_service_time-constants.min_service_time;
int servertime = new Random (). Nextint (maxservertime) +1 + constants.min_service_time;
try {
System.out.println (Windowname + "Start for the first" + Servernum + "General customer Service");
Thread.Sleep (Servertime);
System.out.println (Windowname + "complete for the first" + Servernum + "number of ordinary customer service, total time consuming" + servertime/1000 + "seconds");
catch (Interruptedexception e) {
E.printstacktrace ();
}
}else {
try {
System.out.println (Windowname + "does not take the ordinary task, is idle one second");
Thread.Sleep (1000);
catch (Interruptedexception e) {
E.printstacktrace ();
}
}
}

/**
* Quick Window
*/
private void Expressservice () {
String windowname = "First" + Windownum + "number" + Type + "window";
Integer servernum = Nummachine.getinstance (). Getexpmanager (). Serverwindowfetchnum ();
if (servernum!= null) {
int servertime = Constants.min_service_time;
try {
System.out.println (Windowname + "Start for the first" + Servernum + "fast customer service");
Thread.Sleep (Servertime);
System.out.println (Windowname + "complete for the first" + Servernum + "Fast customer service, total time consuming" + servertime/1000 + "seconds");
catch (Interruptedexception e) {
E.printstacktrace ();
}
}else {
System.out.println (Windowname +) did not get a quick task. ");
Commonservice ();
}
}

/**
* VIP window
*/
private void Vipservice () {
String windowname = "First" + Windownum + "number" + Type + "window";
Integer servernum = Nummachine.getinstance (). Getvipmanager (). Serverwindowfetchnum ();
if (servernum!= null) {
int maxservertime = Constants.max_service_time-constants.min_service_time;
int servertime = new Random (). Nextint (maxservertime) +1 + constants.min_service_time;
try {
System.out.println (Windowname + "beginning for the first" + Servernum + "VIP customer Service");
Thread.Sleep (Servertime);
System.out.println (Windowname + "complete for the first" + Servernum + "VIP customer service, total time consuming" + servertime/1000 + "seconds");
catch (Interruptedexception e) {
E.printstacktrace ();
}
}else {
System.out.println (Windowname + ") did not take the VIP task. ");
Commonservice ();
}
}

}

For customer-facing people:

Public class Customerfetchmachine {
 
 public static void Commfetchnum () {
   Executors.newscheduledthreadpool (1). Scheduleatfixedrate (
    new Runnable () {
      public void Run () {
      integer servicenumber = Nummachine.getinstance (). Getcommmanager (). Clientfetchnum ();
      system.out.println ("+ Servicenumber +") normal customer is waiting for service. ");       
     }
    ,
    0,
    constants.common_customer_interval_time,
     timeunit.seconds);
 }

 public static void Vipfetchnum () {
  executors.newscheduledthreadpool (1). scheduleatfixedrate (
    new Runnable () {
     public void Run () {
       integer Servicenumber = Nummachine.getinstance (). Getvipmanager (). ClientFetchNum ();
      system.out.println ("the" + Servicenumber + "VIP customer is waiting for service.) ");
     }
    },
    0,
    constants.common_ Customer_interval_time * 6,
    timeunit.seconds);
 }

public static void Expfetchnum () {
Executors.newscheduledthreadpool (1). Scheduleatfixedrate (
New Runnable () {
public void Run () {
Integer Servicenumber = Nummachine.getinstance (). Getexpmanager (). Clientfetchnum ();
System.out.println ("No." + Servicenumber +) Fast customer is waiting for service. ");
}
},
0,
Constants.common_customer_interval_time * 2,
Timeunit.seconds);
}
}

2, the number management design

The number used to manage a single window:

public class Nummanager {
private int num = 0;
Private List queuenums = new ArrayList ();
Public synchronized Integer Clientfetchnum () {
Queuenums.add (++num);
return num;
}
Public synchronized Integer Serverwindowfetchnum () {
if (queuenums.size () > 0) {
Return (Integer) queuenums.remove (0);
}
return null;
}
}

The number used to manage all windows:

public class Nummachine {
private static Nummachine instance = new Nummachine ();
Private Nummanager Commmanager = new Nummanager ();
Private Nummanager Expmanager = new Nummanager ();
Private Nummanager Vipmanager = new Nummanager ();
Private Nummachine () {}

Public Nummanager Getcommmanager () {
return commmanager;
}

Public Nummanager Getexpmanager () {
return expmanager;
}

Public Nummanager Getvipmanager () {
return vipmanager;
}

public static Nummachine getinstance () {
return instance;
}
}

Write a test class simulation:

public class Test {

/**
* @param args
*/
public static void Main (string[] args) {

Generates 4 normal windows
for (int i=1;i<5;i++) {
Serverwindow win = new Serverwindow ();
Win.settype (Customertype.common);
Win.setwindownum (i);
New Thread (Win). Start ();
}
Generates 1 VIP Windows
Serverwindow Vipwin = new Serverwindow ();
Vipwin.settype (CUSTOMERTYPE.VIP);
Vipwin.setwindownum (6);
New Thread (Vipwin). Start ();

Generate 1 Quick Windows
Serverwindow Expwin = new Serverwindow ();
Expwin.settype (customertype.express);
Expwin.setwindownum (5);
New Thread (Expwin). Start ();

Analog User id: Ordinary customers, VIP customers, fast customers
Customerfetchmachine.commfetchnum ();
Customerfetchmachine.vipfetchnum ();
Customerfetchmachine.expfetchnum ();
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.