7K面试题之银行业务管理
来源:互联网 发布:sql获得系统时间 编辑:程序博客网 时间:2024/06/06 03:47
思路:
到银行处理业务的步骤为: 先到取号机取号,服务器叫号,服务,服务完毕
银行服务窗口办理的业务可分为普通业务,快速业务,VIP业务
办理普通业务,快速业务,VIP业务的比例分别为6:3:1;
根据分析转换成JAVA对象
创建一个号码管理,来一个客户往里添加一个号码,服务台处理一个用户,从号码管理器中删除一个号码
创建一个号码管理的机器,里面可以创建VIP业务,快速业务,普通业务相应的号码管理器,并设置get方法取得相应的管理器,由于只有一台机器管理有的业务类型,所以此类为单例的类。
创建一个服务台类,
1、创建一个方法开启服务,当服务器服务开启以后,就可以来一个客户,往相应类型里面添加一个号码。
2、创建每个业务的执行类,传入相应的窗口类型,如果快速窗口和VIP窗口当前没有客户,则等一秒后取普通窗口的客户服务
3、创建一个枚举类型,并设置VIP,快速,普通类型
4、创建一个线程池,并执行while(true),并判断当前业务类型,让当前服务窗口不间断的服务。
5、创建一个主要调用的类。创建窗口对象,调用开始服务窗口,这时不断的用号码管理器中添加相应业务的号码
6、在主要调用的类中创建普通,快速,VIP窗口,并调用开始办理业务的方法;
示例代码:
先创建一个号码管理器
package bank;import java.util.ArrayList;import java.util.List;public class NumManager {private List<Integer> numList = new ArrayList();private int i = 0;public synchronized Integer numAdd() {i++;numList.add(i);return i;}public synchronized Integer removeAdd() {if (numList.size() > 0) {return numList.remove(0);}return null;}}
创建一个号码管理台,管理所有业务的号码管理器
package bank;public class NumControllMachine {NumManager vipNumManager = new NumManager();NumManager expressNumManager = new NumManager();NumManager commonNumManager = new NumManager();public NumManager getVipNumManager() {return vipNumManager;}public NumManager getExpressNumManager() {return expressNumManager;}public NumManager getCommonNumManager() {return commonNumManager;}private NumControllMachine() {}private static NumControllMachine numControlMachine = new NumControllMachine();public static NumControllMachine getInstance() {return numControlMachine;}}
创建一个枚举类型,并创建相应的对象
package bank;public enum BusinessType {COMMON, EXPRESS, VIP;public String toString() {switch (this) {case COMMON:return "普通";case EXPRESS:return "快速";case VIP:return "VIP";default:return null;}};}
创建时间管理类,并建立全局参数(最大服务时间,最短服务时间《快速业务为最短服务时间》)
package bank;public class ServiceTime {public static int MAX_SERVICE_TIME = 6000;public static int MIN_SERVICE_TIME = 1000;}
建立服务窗口类
package bank;import java.util.Random;import java.util.concurrent.Executor;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;public class ServerWindow {private NumControllMachine numcontrollMachine = NumControllMachine.getInstance();private int windowId;public ServerWindow(int windowId, BusinessType type) {super();this.windowId = windowId;this.type = type;}private BusinessType type;/*
*根据各窗口办理什么业务,调用相应的方法
*/
public void callNum() {Executors.newSingleThreadExecutor().execute(new Runnable() {@Overridepublic void run() {while (true) {switch (type) {case COMMON:commonServer(type);break;case EXPRESS:expressServer(type);break;case VIP:vipServer(type);break;}}}});}public void commonServer(BusinessType type) {Integer removeClicentId = numcontrollMachine.getCommonNumManager().removeAdd();if (removeClicentId == null) {System.out.println(windowId + "号" + type + "窗口没有取到"+ BusinessType.COMMON + "任务,等待1秒");try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}} else {try {System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.COMMON + "业务的" + removeClicentId+ "号客户服务");long startTime = System.currentTimeMillis();int randomTime = ServiceTime.MIN_SERVICE_TIME+ (ServiceTime.MAX_SERVICE_TIME - ServiceTime.MIN_SERVICE_TIME);Thread.sleep(new Random().nextInt(randomTime));long winSerTime = (System.currentTimeMillis() - startTime) / 1000;System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.COMMON + "业务的" + removeClicentId+ "号客户服务完毕,服务时间为" + winSerTime);} catch (InterruptedException e) {e.printStackTrace();}}}public void expressServer(BusinessType type) {Integer removeClicentId = numcontrollMachine.getExpressNumManager().removeAdd();if (removeClicentId == null) {try {System.out.println(windowId + "号" + type + "窗口没有取到"+ BusinessType.EXPRESS + "任务,等待1秒");Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}commonServer(type);} else {try {System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.EXPRESS + "业务的" + removeClicentId+ "号客户服务");long startTime = System.currentTimeMillis();Thread.sleep(ServiceTime.MIN_SERVICE_TIME);long winSerTime = (System.currentTimeMillis() - startTime) / 1000;System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.EXPRESS + "业务的" + removeClicentId+ "号客户服务完毕,服务时间为" + winSerTime);} catch (InterruptedException e) {e.printStackTrace();}}}public void vipServer(BusinessType type) {Integer removeClicentId = numcontrollMachine.getVipNumManager().removeAdd();if (removeClicentId == null) {try {System.out.println(windowId + "号" + type + "窗口没有取到"+ BusinessType.VIP + "任务,等待1秒");Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}commonServer(type);} else {try {System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.VIP + "业务的" + removeClicentId + "号客户服务");long startTime = System.currentTimeMillis();int randomTime = ServiceTime.MIN_SERVICE_TIME+ (ServiceTime.MAX_SERVICE_TIME - ServiceTime.MIN_SERVICE_TIME);Thread.sleep(randomTime);long winSerTime = (System.currentTimeMillis() - startTime) / 1000;System.out.println(windowId + "号" + type + "窗口开始为办理"+ BusinessType.VIP + "业务的" + removeClicentId+ "号客户服务完毕,服务时间为" + winSerTime);} catch (InterruptedException e) {e.printStackTrace();}}}
/**
*开启服务用号码管理器中添加新来的用户
*/public void start() {Executors.newSingleThreadScheduledExecutor().execute(new Runnable() {@Overridepublic void run() {while (true) {try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}int addClientId = numcontrollMachine.getCommonNumManager().numAdd();System.out.println("办理" + BusinessType.COMMON + "业务 的"+ addClientId + "号客户等待服务");}}});Executors.newSingleThreadScheduledExecutor().execute(new Runnable() {@Overridepublic void run() {while (true) {try {Thread.sleep(new Random().nextInt(8)*1000+1000);} catch (InterruptedException e) {e.printStackTrace();}int addClientId = numcontrollMachine.getExpressNumManager().numAdd();System.out.println("办理" + BusinessType.EXPRESS + "业务 的"+ addClientId + "号客户等待服务");}}});Executors.newSingleThreadScheduledExecutor().execute(new Runnable() {@Overridepublic void run() {while (true) {try {Thread.sleep(new Random().nextInt(17) * 1000 + 1000);} catch (InterruptedException e) {e.printStackTrace();}int addClientId = numcontrollMachine.getVipNumManager().numAdd();System.out.println("办理" + BusinessType.VIP + "业务 的"+ addClientId + "号客户等待服务");}}});}}
建立调用的类:开启各个服务窗口,并开始服务
package bank;public class MainService {public static void main(String[] args) {for (int i = 1; i <= 5; i++) {ServerWindow comSerWin = new ServerWindow(i, BusinessType.COMMON);comSerWin.start();comSerWin.callNum();}ServerWindow expressWin = new ServerWindow(6, BusinessType.EXPRESS);expressWin.start();expressWin.callNum();ServerWindow vipWin = new ServerWindow(7, BusinessType.VIP);vipWin.start();vipWin.callNum();}}
---------------------- ASP.Net+Android+IO开发 Net培训期待与您交流! ----------------------
详细请查看http://edu.csdn.net
- 7K面试题之银行业务管理
- 7K面试题,银行业务
- (18) - 银行业务调度管理系统(7k面试题)
- 黑马程序员7K面试题:银行业务管理系统
- 黑马程序员--7K面试题之银行业务调度系统
- 黑马程序员-7k面试题之银行业务调度系统
- 黑马程序员 7K面试题之银行业务调度系统
- 黑马程序员:7K面试题之银行业务调度系统
- 1--黑马程序员--7k面试题之银行业务系统
- 黑马程序员-----7K面试题之银行业务调度系统
- 7k面试题-银行业务调度系统
- 7K面试题银行业务调度系统
- 【黑马程序员】 学习笔记 - 直击7K面试题 - 张孝祥老师的银行业务调度管理系统
- 黑马程序员之7k面试题之银行业务调度系统
- 黑马程序员——张孝祥老师7k面试题之银行业务调度
- 奋斗黑马程序员----7k月薪面试题之银行业务调度系统
- 黑马程序员 7K月薪面试题破解之二 -- 银行业务调度系统
- 黑马程序员 Java基础 --->7K面试题之银行业务调度系统
- Rserve与Java的跨平台通信
- ssh 上传文件到隔离虚拟机中
- Layered Window(分层窗体,透明窗体)
- java程序员面试宝典(3)
- 【加密】
- 7K面试题之银行业务管理
- __FILE__和__LINE__的使用
- java基础_final,static,volatile
- 第7章 方法
- jdk、oracle、js、activeX的base64实现
- linux下C编程(文件相关)
- VC连接ODBC数据
- 为MySQL数据文件ibdata1瘦身
- b树index和bitmap索引