Interview questions Bank Business scheduling System _ Interview

Source: Internet
Author: User
Tags time interval


Bank Business Dispatch System

Simulation to achieve the logic of banking scheduling system, the specific requirements are as follows:

Ø There are 6 business windows in the Bank, window 1-4 is a normal window, window 5th is a quick window, and 6th window is the VIP window.

Ø There are three types of customers: VIP customers, ordinary customers, fast customers (handling such as electricity and water charges, such as customer service charges).

Ø randomly generate various types of customers, the probability of generating various types of users is:

VIP Customers: Ordinary customers: Fast customer = 1:6: 3.

Ø the customer needs to handle the business time has the maximum and the minimum value, in this range randomly sets each VIP customer as well as the ordinary customer handles the business time, the fast customer handles the business the time to be minimum value (hint: the process of handling the business can be simulated by thread sleep way).

Ø various types of customers in their corresponding windows in order to transact business.

Ø when the VIP (number 6th) window and Fast Service (5th) window does not have customers waiting for business, these two windows can handle the business of ordinary customers, and once the corresponding customer waiting for business, then priority to deal with the business of the corresponding customer.

Ø randomly generate customer time interval and business processing time maximum and minimum custom, you can set.

Ø does not require the implementation of the GUI, only consider the system logic implementation, can display the results of the program log.

Technology to use:

1. Object-oriented design

2, the use of thread pool

3, enumeration

4. Single Case design mode

Main methods of design in class: Numbermanager-----Production Number and number

Numbermachine------equivalent to the bank's automatic pickup machine, single case design, can produce 3 different types of numbers

Servicewindow-----Equivalent to the Bank's window, with a station, processing functions

Main code implementation:

Numbermanager

Publicclassnumbermanager {

privateintlastnumber=0;

List<integer>queuenumbers=new arraylist<integer> ();

publicsynchronized Integer Generatenumber () {

Queuenumbers.add (++lastnumber);

Returnlastnumber;

}

publicsynchronized Integer Fetchnumber () {

if (Queuenumbers.size () >0)

Returnqueuenumbers.remove (0);

Else

Returnnull;

}

}

Numbermachine:

Package Cn.itcast.bank;

Publicclassnumbermachine {

Private Numbermachine () {}

Publicstaticnumbermachineinstance=newnumbermachine ();

Publicstaticnumbermachine getinstance () {

Returninstance;

}

Private Numbermanagercommonmanager=new Numbermanager ();

Private Numbermanagerfastmanager=new Numbermanager ();

Private Numbermanagervipmanager=new Numbermanager ();

Public Numbermanager Getcommommanager () {

Returncommonmanager;

}

Public Numbermanager Getfastmanager () {

Returnfastmanager;

}

Public Numbermanager Getvipmanager () {

Returnvipmanager;

}

}

Servicewindow

Package Cn.itcast.bank;

Import Java.util.Random;

Import java.util.concurrent.Executors;

Publicclassservicewindow {

Private Customertypetype = Customertype.common;

Privateintnumber = 1;

Publicvoid setType (customertype type) {

This.type = type;

}

publicvoid setnumber (int number) {

This.number = number;

}

Publicvoid Start () {

Executors.newsinglethreadexecutor (). Execute (new Runnable () {

Publicvoid Run () {

while (true) {

Switch (type) {

Casecommon:

Commonservice ();

Break

Casefast:

Fastservice ();

Break

CASEVIP:

Vipservice ();

Break

}

}

}

});

}

Privatevoid Commonservice () {

String Windowname = "+number +" number "+type +" window;

System.out.println (Windowname + "start to get ordinary tasks");

Integer Servicenumber = Numbermachine.getinstance (). Getcommommanager ()

. Fetchnumber ();

if (Servicenumber!=null) {

System.out.println (Windowname + "start as" + Servicenumber + "General customer Service");

int time =new Random (). Nextint (10) + 1;

try {

Thread.Sleep (time);

catch (Interruptedexception e) {

E.printstacktrace ();

}

SYSTEM.OUT.PRINTLN ("Complete for" + Servicenumber + "Ordinary customer service, time-consuming" + time

+ "seconds");

} else {

System.out.println (Windowname + "not get the normal task, is idle for a second");

try {

Thread.Sleep (1000);

catch (Interruptedexception e) {

E.printstacktrace ();

}

}

}

Privatevoid Fastservice () {

String Windowname = "+number +" number "+type +" window;

System.out.println (Windowname + "Start getting quick task");

Integer Servicenumber = Numbermachine.getinstance (). Getfastmanager ()

. Fetchnumber ();

if (Servicenumber!=null) {

System.out.println (Windowname + "start as" + Servicenumber + "fast customer service");

int time =new Random (). Nextint (5) + 1;

try {

Thread.Sleep (time);

catch (Interruptedexception e) {

E.printstacktrace ();

}

SYSTEM.OUT.PRINTLN ("Complete for" + Servicenumber + "Fast customer service, time-consuming" + time

+ "seconds");

} else {

System.out.println (Windowname + "No quick task is getting ready to get common tasks");

Commonservice ();

}

}

Privatevoid Vipservice () {

String Windowname = "+number +" number "+type +" window;

System.out.println (Windowname + "start to get VIP task");

Integer Servicenumber = Numbermachine.getinstance (). Getcommommanager ()

. Fetchnumber ();

if (Servicenumber!=null) {

System.out.println (Windowname + "start as" + Servicenumber + "VIP customer Service");

int time =new Random (). Nextint (8) + 1;

try {

Thread.Sleep (time);

catch (Interruptedexception e) {

E.printstacktrace ();

}

System.out.println ("complete the" + Servicenumber + "VIP customer service, time-consuming" + time

+ "seconds");

} else {

System.out.println (Windowname + "not get VIP task, is preparing to get common task");

Commonservice ();

}

}

}


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.