Bank Service Dispatch System

Source: Internet
Author: User

First, the demand of banking operation dispatching system

Simulation of the implementation of the banking business scheduling system logic, the specific requirements are as follows:

    • There are 6 business windows in the Bank, window 1-4 is normal window, window 5th is Quick window, window 6th is VIP window.

    • There are three types of customers: VIP customers, ordinary customers, fast customers (for example, to pay utilities, such as electricity charges, such as business customers).

    • Asynchronously randomly generates various types of customers, and the probability ratio for generating types of users is:

VIP Customer: Ordinary customer: Fast customer = 1:6: 3.

    • The time required for the customer to transact the business is the maximum and minimum, in which the time required for each VIP customer and the ordinary customer to transact the business is randomly set, and the time required for the fast customer to transact the business is the minimum (hint: the process of processing the business can be simulated by thread sleep).

    • Various types of customers in their corresponding window in order to transact business sequentially.

    • When the VIP (6th) window and the Fast Business (5th) window do not have customers waiting for business, these two windows can handle the business of ordinary customers, and once the corresponding customers waiting for the business, the priority is to deal with the customer's business.

    • Randomly generated customer time interval and business processing time maximum and minimum value custom, can be set.

    • Does not require the implementation of the GUI, only consider the implementation of the system logic, log mode can show the program running results.

Second, object-oriented analysis and design:

1, there are three types of customers: VIP customers, ordinary customers, fast customers, asynchronous random generation of various types of customers, all types of customers in their corresponding window in order to transact business sequentially.

> First, to the bank to do business, first to obtain a number, which is similar to registered, and then the bank's staff based on the number generated by the computer to serve customers.  This requires a number manager object, so that the object constantly generate numbers, it is equal to randomly generated customers. > Since there are three types of customers, each type of customer's number orchestration is completely independent, so, the system to generate a total of three number manager object, each management of a class of users queue number.   These three number manager objects are managed by a number machine, and this number machine can only have one in the whole system, so it should be designed as a singleton.  2, various types of customers in their corresponding window in order to transact business in sequence, to be precise, should be the window in turn call. > How does each window know which number to call? It must be asking for the corresponding number manager, which is the service window each time the number manager gets the number that is currently being serviced.

> Using class diagrams to analyze comprehension:


A number generator Numbermachine management three types of number of ordinary users, VIP users, fast users. The Numbermanager class is used to generate the number, and to obtain the number. And Servicewindow gets the number in Numbermanager.

Iii. Preparation of:

Numbermanager class

> defines a member variable to store the previous customer number and a collection of queues to store all the customer numbers waiting for the service. > defines a method for generating a new number and getting the number to be serviced immediately, and the two methods are manipulated by different threads for the same data, so synchronize.
1 package com.itheima.www; 2  3 import java.util.ArrayList; 4 import java.util.List; 5  6 public class Numbermanager {7/     * Returns the last number returned */8
   private int lastnumber = 1;  9     /* For storing all waiting service customer number queues */10     private list<integer> queuenumber = new arraylist<integer> ();     **12          the method of generating new number          @return The newly generated number      */15 public     synchronized Integer Generatenewmanager () {         Queuenumber.add (Lastnumber);         lastnumber++     }19     /**21          Get the number you want to service immediately         @return Number 23 to be served immediately     */24 public     synchronized Integer Fetchservicenumber () {         if (queuenumber.size () > 0) {             Return Queuenumber.remove (0); +         else {             return null;         }31     }32     33}

Numbermachine class

> defines three member variables to point to three Numbermanager objects, respectively, the number manager for normal, fast, and VIP customers, and defines three corresponding methods to return the three Numbermanager objects. > Design the Numbermachine class into a single case.
1 package com.itheima.www; 2  3 public class Numbermachine {4     * * Represents a regular customer's number Manager */5     private Numbermanager Commonmanager = new Numbermanager () ; 6     /* Represents the fast customer's number Manager *     /7 private Numbermanager Expressmanager = new Numbermanager (); 8/     * represents the VIP customer's number Manager */9     private Numbermanager Vipmanager = new Numbermanager (),     private Numbermachine () {}     private static Numbermachine numbermachine = null; Public     static Numbermachine getinstance () {         numbermachine = = null) {             numbermachine = new Numbermachine ();         }18         return numbermachine,}20 public     Numbermanager Getcommonmanager () {         Return commonmanager;23     }24 public     Numbermanager Getexpressmanager () {         return expressmanager;26     }27 public     Numbermanager Getvipmanager () {         vipmanager;29     } 30}

CustomerType Enumeration Classes > Systems have three types of customers, so define an enumeration class that defines three members representing three types of customers respectively. > Overrides the ToString method, which returns the Chinese name of the type. This is reconstructed at the back of the code and is not considered at first.
1 package com.itheima.www; 2  3 public enum CustomerType {4     common,express,vip; 5      6 Public     String toString () {7         switch (this) { 8 Case         Common:9             return "normal",         express:11             return "Fast",         default:13             return "VIP", 14< C12/>}15     }16}


Servicewindow class > Defines a start method that internally initiates a thread that loops through three different methods, respectively, according to the category of the service window. > defines three methods to service three kinds of customers, in order to observe the effect of operation, should print out the details of the detailed information.
  1 package com.itheima.www;  2 3 Import Java.util.Random;  4 Import java.util.concurrent.Executors;  5 6 public class Servicewindow {7 * * Customer type */8 private CustomerType type = NULL; 9 private int number = 1; Ten public CustomerType GetType () {n-return type; and the public void SetType (Customertyp E type) {this.type = type; +} public void Setnumber (int number) {This.number = Nu Mber;             () {Executors.newsinglethreadexecutor (). Execute (new Runnable () {25                             public void Run () {+ switch (type) {common:28  while (true) {Commonservice (); $3 Case express:32 while (true)  3 Expressservice ();                 34            } vip:36 while (true) {37  Vipservice (); 38} 39} 40} 41}); Commonservice () {45 */* Get the number to be serviced */* Servicenumber = Numbermac Hine.getinstance (). Getcommonmanager (). Fetchservicenumber (); String windowname = type + "Window _" + number + "No."; System.out.println (Windowname + ": Get started-common tasks! "); $ if (servicenumber! = null) {System.out.println (Windowname + ": Start with" +servicenumber+ "-Normal user-start service" ); 51 * * Service time between the maximum and minimum values for a normal user */Amongtime int = Custants.max_service_time-custants.min_service_tim E serivcetime int = new Random (). Nextint (Amongtime) + 1 + custants.min_service_time; # try {thread.sleep (serivcetime);) catch (Interruptedexception e) {//TODO auto-generated catch block E.printstacktrace (); 59} 60 System.out.println (Windowname + ": Completed for the first" +servicenumber+ "-General customer service, total time spent" + serivcetime/1000 + "Seconds"); SYSTEM.OUT.PRINTLN} + Else {windowname + ": Not taken-normal task! Take a second off! ");                 try {thread.sleep (+), + +} catch (Interruptedexception e) {68 TODO auto-generated Catch block E.printstacktrace (); (+}) (+) * Expressservice} (private void) {74 */* Get the number to service * * Ervicenumber = Numbermachine.getinstance (). Getexpressmanager (). Fetchservicenumber (); Windowname String = type + "Window _" + number + "No."; System.out.println (Windowname + ": Get started-quick quests! "); if (servicenumber! = null) {System.out.println (Windowname + ": Starts with the" +servicenumber+ "number-Fast user-onService "); 80/* Fast User Service time between the maximum and minimum values */bayi int serivcetime = Custants.min_service_time;                 Thread.Sleep (serivcetime); catch (Interruptedexception e) {85 TODO auto-generated Catch block E.printstacktrace ();                     System.out.println (Windowname + ": Completed for section" +servicenumber+ "-fast customer service, total time consuming" 89 + serivcetime/1000 + "seconds"); "System.out.println" (Windowname + ": Not taken to-fast task! "); Commonservice (); 94} vipservice {97 */* To get the number to service */98 Integer Servicenumber = Numberm Achine.getinstance (). Getvipmanager (). Fetchservicenumber (); Windowname String = type + "Window _" + number + "sign"; System.out.println (Windowname + ": Get started-common tasks!) "); 101 if (servicenumber! = null) {102 SYSTEM.OUT.PRINTLN (Windowname +": Start for section "+servicenumber+ "-VIP User-start service"); 103/*VIP The service time of the user between the maximum and minimum values */104 int amongtime = Custants.max_service_time- custants.min_service_time int serivcetime = new Random (). Nextint (Amongtime) + 1 + custants.min_service_t IME; 106 try {107 thread.sleep (serivcetime); 108} catch (Interruptedexception e)             {109//TODO auto-generated catch block110 e.printstacktrace (); 111}112 System.out.println (Windowname + ": Completed for the first" +servicenumber+ "-VIP customer service, total time-consuming" 113 + serivcetime/1000 + "seconds") ;}115 else {System.out.println (Windowname + "): No-VIP task is taken! "); 117 Commonservice (); 118}119}120}

MainClass class

> creates 4 normal windows with a for loop, and then creates 1 quick windows and a VIP window. > Then create three timers to create a new regular customer number, a new fast customer number, and a new VIP customer number, respectively.
 1 package com.itheima.www; 2 3 Import java.util.concurrent.Executors; 4 Import Java.util.concurrent.TimeUnit; 5 6 public class MainClass {7 public static void Main (string[] args) {8//Create 4 normal Windows 9 for (int i = 1 ; I < 5; ++i) {Servicewindow window = new Servicewindow (); Window.setnumber (i); Windo W.settype (Customertype.common); Window.start (); 14}15//create 1 quick Windows Servicewindow E  Xpresswindow = new Servicewindow (); Expresswindow.settype (; Expresswindow.start (); 19 20//Wear a VIP window  Servicewindow Vipwindow = new Servicewindow ();         Vipwindow.settype (CUSTOMERTYPE.VIP); Vipwindow.start (); 24 25//Regular client number 26 created separately                         Executors.newscheduledthreadpool (1). Scheduleatfixedrate (New Runnable () {public void run () {28 Integer Servicenumber = Numbermachine.getinstance (). Getcommonmanager (). Generatenewmanager (); System.out.println ("Customer: section" + Servicenumber + "#-Ordinary customers-waiting for service! ");}31}32, 033, Custants.common_customer_interva L_time, timeunit.seconds); 35//The Fast client number created on a timed basis is executors.newscheduledthreadpool (1). SC Heduleatfixedrate (New Runnable () {PNs public void Run () {$ Integer Servicenumbe R = Numbermachine.getinstance (). Getexpressmanager (). Generatenewmanager (), System.out.println ("Guest User: section "+ Servicenumber +"-Fast customer-waiting for service! ");}41}42, 043, Custants.common_customer_interva L_time * 344, timeunit.seconds); 45//VIP client number created on a timed basis Executors.newscheduledthreadpool (1 ). Scheduleatfixedrate (New Runnable () {public void RuN () {Integer servicenumber = Numbermachine.getinstance (). Getvipmanager (). Generatenewmanager (); System.out.println ("Customer: First" + Servicenumber + "No.-VIP Customer-waiting for service! ");}51}52, 053, Custants.common_customer_interva L_time * 654, timeunit.seconds); 55}56}

Constants Class > defines three constants: Max_service_time, Min_service_time, Common_customer_interval_time
1 Package com.itheima.www;2 3 public class Custants {4 public     static int min_service_time = 5, public     static int max_service_time = 10000; 6     7 public     static int common_customer_interval_time = 1; 8}

Summary: In the writing of this kind of simulation project only enough understanding of the business process to complete the writing, and only in the business process enough to understand, in order to object-oriented design and analysis to more accurately define the various objects in the project, as well as object-owned methods, objects and the relationship between the object. Come on!

Department reprint

Bank Service Dispatch System

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: 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.