-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------
Simulating the implementation of bank service dispatching system
1. The specific requirements are as follows:
(1). There are 6 Business Windowsin the bank,1-4 window is Normal window,window5 is Quick window,window6 is VIP window.
(2). There are three types of customers:VIP customers, ordinary customers, fast customers
(3). asynchronously generates various types of customers randomly, the probability ratio of generating various kinds of users is:
VIP Customer: Ordinary customer: Fast customer = 1 :6 :3
(4). the time required for the customer to transact the business has the maximum and minimum value, in this range randomly set each VIP Customer and the ordinary customer to transact the business time,
The minimum time required for a fast customer to transact a business. randomly generated customer time intervals and business processing time maximum and minimum custom, you can set
(5). various types of customers in their corresponding window in order to transact business
(6). when the VIP(6 ) window and the Fast service (5 ) window do not have customers waiting for business, These two windows can handle the business of a regular customer,
And once the corresponding customer waits for the business, the priority is to deal with the customer's business
2. Object-oriented requirements 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
A. First of all, be aware that each customer is actually represented by a number machine in the bank that produces numbers. So, think about having a number manager object that lets this object
Constant generation of numbers is tantamount to randomly generating a customer.
B. Secondly, because there are three types of customers, each type of customer's numbering is completely independent, so, think of this system altogether to generate three number manager objects, each management of a class of users
Number of queues. 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 is designed as a singleton
This in real life to the bank to transact business process is also consistent, only a number generator, on this machine has different business for customers to choose
(2). Each type of customer in their corresponding window in order to transact business sequentially, 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.
(3). From the above analysis can be created the following
Several classes:
Numbermachine class, Numbermanager class, Serverwindow class and MainClass class, and necessary auxiliary constant class (Constants) and enumeration class (CustomerType)
3. The Code implementation process:
(1). Create a Numbermachine class
A. Define three member variables to point to three Numbermanager objects, representing regular, fast, and VIP customer number managers, and define three corresponding methods to return the three
A Numbermanager object.
B. Designing the Numbermachine class into a single case
(2). Create a Numbermanager class
A. Define a member variable to store the previous customer number and a collection of queues to store all the customer numbers waiting for the service.
B. Define a method for generating a new number and get the number to be serviced immediately, and the two methods are manipulated by different threads for the same data, so synchronize.
(3). Create an auxiliary CustomerType enumeration class
A. There are three types of customers in the system, so define an enumeration class that defines three members representing three types of customers, respectively.
B. Overriding the ToString method, returning the Chinese name of the type
(4). Create Auxiliary constants Constant class
Define three constants: Max_service_time, Min_service_time, Common_customer_interval_time
(5). Create a Serverwindow class
A. Define a start method that internally initiates a thread that loops through three different methods according to the category of the service window.
B. Define three methods to service three kinds of customers, and in order to observe the effect of operation, detailed information should be printed out in detail.
(6). Create MainClass
A. Create 4 normal windows with a for loop, then create 1 quick windows and a VIP window.
B. Then create three timers to create a new regular customer number, a new fast customer number, a new VIP customer number, respectively.
4. Run the Debug results:
5. Summary and Reflection
The analysis process of the business is actually using object-oriented thinking, which classes and objects have relevant data, must provide the corresponding functions and methods of this principle, abstract
The corresponding class, the required member variables, methods, static methods, construction methods and other content to create, and use Java to achieve!
Dark Horse Programmer--analysis and design of banking dispatching system and implementation of Java code