黑马程序员————银行业务调度2
来源:互联网 发布:网络机顶盒如何更新 编辑:程序博客网 时间:2024/06/06 14:18
CustomerType枚举类
> 系统中有三种类型的客户,所以用定义一个枚举类,其中定义三个成员分别表示三种类型的客户。
> 重写toString方法,返回类型的中文名称。这是在后面编码时重构出来的,刚开始不用考虑。
package com.itheima.www;public enum CustomerType { COMMON,EXPRESS,VIP ; public String toString() { switch(this) { case COMMON: return "普通" ; case EXPRESS: return "快速" ; default: return "VIP" ; } }}
<div style="font-family: 微软雅黑, 宋体, Arial; font-size: 15px;"><span style="font-size: 14pt;">ServiceWindow类</span></div><div class="O1" style="font-family: 微软雅黑, 宋体, Arial; font-size: 15px;"> > 定义一个start方法,内部启动一个线程,根据服务窗口的类别分别循环调用三个不同的方法。</div><div class="O1" style="font-family: 微软雅黑, 宋体, Arial; font-size: 15px;"> > 定义三个方法分别对三种客户进行服务,为了观察运行效果,应详细打印出其中的细节信息。</div><pre name="code" class="java">package com.itheima.www;import java.util.Random;import java.util.concurrent.Executors;public class ServiceWindow { /*客户的类型*/ private CustomerType type = null ; private int number = 1 ; public CustomerType getType() { return type; } public void setType(CustomerType type) { this.type = type; } public void setNumber(int number) { this.number = number; } public void start() { Executors.newSingleThreadExecutor().execute(new Runnable(){ public void run() { switch(type){ case COMMON : while(true){ commonService() ; } case EXPRESS : while(true){ expressService() ; } case VIP: while(true){ vipService() ; } } } }) ; } private void commonService(){ /*获取要服务的号码*/ Integer serviceNumber = NumberMachine.getInstance().getCommonManager().fetchServiceNumber() ; String windowName = type + "窗口_第" + number + "号" ; System.out.println(windowName + ":开始获取-普通任务!"); if( serviceNumber != null) { System.out.println(windowName + ":开始为第"+serviceNumber+"号-普通用户-开始服务"); /*普通用户的服务时间在最大值和最小值之间*/ int amongTime = Custants.MAX_SERVICE_TIME - Custants.MIN_SERVICE_TIME ; int serivceTime = new Random().nextInt(amongTime) + 1 + Custants.MIN_SERVICE_TIME ; try { Thread.sleep(serivceTime) ; } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(windowName +":完成为第"+serviceNumber+"号-普通客户服务,总耗时" + serivceTime/1000 +"秒"); } else { System.out.println(windowName +":没有取到-普通任务!休息一秒!"); try { Thread.sleep(1000) ; } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private void expressService() { /*获取要服务的号码*/ Integer serviceNumber = NumberMachine.getInstance().getExpressManager().fetchServiceNumber() ; String windowName = type + "窗口_第" + number + "号" ; System.out.println(windowName + ":开始获取-快速任务!"); if( serviceNumber != null) { System.out.println(windowName + ":开始为第"+serviceNumber+"号-快速用户-开始服务"); /*快速用户的服务时间在最大值和最小值之间*/ int serivceTime = Custants.MIN_SERVICE_TIME ; try { Thread.sleep(serivceTime) ; } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(windowName +":完成为第"+serviceNumber+"号-快速客户服务,总耗时" + serivceTime/1000 +"秒"); } else { System.out.println(windowName +":没有取到-快速任务!"); commonService() ; } } private void vipService(){ /*获取要服务的号码*/ Integer serviceNumber = NumberMachine.getInstance().getVipManager().fetchServiceNumber() ; String windowName = type + "窗口_第" + number + "号" ; System.out.println(windowName + ":开始获取-普通任务!"); if( serviceNumber != null) { System.out.println(windowName + ":开始为第"+serviceNumber+"号-VIP用户-开始服务"); /*VIP用户的服务时间在最大值和最小值之间*/ int amongTime = Custants.MAX_SERVICE_TIME - Custants.MIN_SERVICE_TIME ; int serivceTime = new Random().nextInt(amongTime) + 1 + Custants.MIN_SERVICE_TIME ; try { Thread.sleep(serivceTime) ; } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(windowName +":完成为第"+serviceNumber+"号-VIP客户服务,总耗时" + serivceTime/1000 +"秒"); } else { System.out.println(windowName +":没有取到-VIP任务!"); commonService() ; } }}
0 0
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- 黑马程序员——银行业务调度系统
- sed 取反
- Windows时间函数
- VS使用Qt库
- 数组合并
- ios内存管理随笔
- 黑马程序员————银行业务调度2
- uva 10131 Is Bigger Smarter?(动态规划:LIS变形+路径打印)
- svn 的三个配置文件样例
- 极端的父爱 湖北校园杀人案嫌犯为女儿上学卖掉租屋
- Servlet/Jsp实现当参数确实或缺失重新显示输入表单
- android与NDK层互相调用类方法
- 如何使用diskpart命令工具来对硬盘或者U盘设定写保护
- 黑马程序员————银行业务调度3
- 狼图腾