Android training , java training , look forward to communicating with you!

 

                         (Dark Horse Programmer) Bank Scheduling System
Design requirements:
 Simulate the logic of the real banking business scheduling system:
1. There is a business window in the bank, 1-4 are ordinary windows, No. 5 is a quick window, and No. 6 is a VIP window.
2. There are three kinds of customers corresponding to the needs: VIP, ordinary, fast (paying water and telephone bills);
3. Asynchronously generate various types of customers randomly, the ratio: VIP: normal: fast = 1: 6: 3;
4. The time required for customers to handle business has a maximum value and a minimum value. Within this range, the time required for each VIP and ordinary customers to handle business is randomly set, and the time required for fast customer processing is the minimum value (the business process can be processed through threads Sleep mode simulation);
5. Each type of customer handles business in sequence in its corresponding window.
6. When there is no customer waiting to handle the business in the VIP window and the express business window, the corresponding customer business will be processed first;
7. The time interval for randomly generating customers and the maximum and minimum value of business processing time are customized and can be set.
Object-Oriented Analysis and Design:
1. Queuing for number fetching: 3 kinds of customers need 3 number generators to obtain their corresponding number types, but there is only one machine for fetching numbers, then 3, there is only one manager, then the singleton design mode is used;
2. Each window calls a number to process business: how does each window know which number to call? Definitely ask the number manager; 
Design legend:
           

 

Note the knowledge points:
1. The variable type should use the parent class as much as possible.
2. The singleton design pattern has three steps: 1. privatize and hide the constructor, 2. create an instance object privately and statically, and 3. expose the method of obtaining the instance object.
Code
  private NumberMachine(){}//
 private static NumberMachine instance = new NumberMachine();
 public static NumberMachine getInstance(){
    return instance;
}
3. Switch is more efficient than if and else if. If it is a limited condition, use switch instead of if structure. The expressions in parentheses after switch can only be integer (byte, short, char and int), enum or character expressions, not long, string or any other type.
Code
public class ServiceWindow{
 private CustomerType Type = CustomerType.COMMON ;/ /CustomerType is an enumeration//enumeration type
 public void start(){
    Executors.newSingleThreadExecutor().execute(new Runnale(){
public void run(){
while(true){
 switch(type){
case COMMON : // The original reference must be CustomerType.COMMON, switchc
............. // The class name can be omitted, but not elsewhere
     break;
.............
}}}})
}}
4. Eclipse usage skills: select all execution statements in the previous case - à right-click, Refactor- à Extract Method- à extract a piece of code into a method.
5. If a certain object needs to continuously process a certain business, the following Code model can be used:
public class ServiceWindow{ // Create this class
  Executors.newSingleThreadExexutor().execute(new Runnable() { // Create a thread//The processing business is different from the thread pool method
  public void run() { // The specific content of the processing
while(ture){ // The condition is set to ture to make this work run continuously
NumberMachine.getInstance().getCommonManager()
.......
}}},)
}

---------------------- android培训java培训、期待与您交流! ---------------------- 详细请查看:http://edu.csdn.net/heima