| 
 模拟银行调度系统 需求:具有六个窗口,四个普通窗口,一个快速窗口,一个vip窗口; 普通窗口:只为普通用户服务。 快速窗口:优先为快速窗口服务,再为普通窗口服务。 VIP窗口,优先为VIP窗口服务,再为普通窗口服务。 服务时间:最大值与最小值,最小值都是快速客户。 客户出现比例。普通:快速:VIP = 6:3:1 模拟用户:自身携带了需要完成的业务,与自身的等级 - public class client implements Comparable<client>
 
 - {
 
 -         private int clientrank;//客户的等级
 
 -         private int clientneed;//客户需求
 
 -         client()
 
 -         {
 
 -                 set();
 
 -         }
 
 -         void set()//初始化客户的需求,与等级
 
 -         {
 
 -                 this.clientrank=(int)(Math.random()*10+1);
 
 -                 if(this.clientrank<4)
 
 -                         this.clientneed=1;
 
 -                 else this.clientneed=(int)(Math.random()*4+2);
 
 -                 System.out.println("产生一个等级为"+getRankString()+"业务为"+clientneed);
 
 -         }
 
 -         public int getClientrank() {
 
 -                 return clientrank;
 
 -         }
 
 -         public int getClientneed() {
 
 -                 return clientneed;
 
 -         }
 
 -         @Override
 
 -         public int compareTo(client o) {
 
 -                 return 1;
 
 -         }
 
 -         public String toString()
 
 -         {
 
 -                 return "等级为"+this.getRankString()+"-----需求为"+this.clientneed;
 
 -         }
 
 -         public String getRankString()
 
 -         {
 
 -                 return this.clientrank<4?"<___快速用户___>":this.clientrank<10?"{___普通用户___}":"【___Vip用户___】";
 
 -         }
 
 - }
 
  复制代码模拟服务窗口:窗口具备向某个银行取出用户的功能,每个窗口都向银行的等候厅取出用户,这里做成线程。 - public class Fram implements Runnable
 
 - {
 
 -         private int rank;
 
 -         private Bank bank;
 
 -         Fram(int rank)//在构造时,就指明窗口的权限
 
 -         {
 
 -                 this.rank=rank;
 
 -                 bank=Bank.getBank();//指定为某个银行服务
 
 -         }
 
 -         public void run()
 
 -         {
 
 -                 while(true)
 
 -                 {
 
 -                         if(this.rank==1)//窗口等级化
 
 -                                 mommon();
 
 -                         else if(this.rank==2)
 
 -                                 quick();
 
 -                         else 
 
 -                                 VIP();
 
 -                 }
 
 -         }
 
 -         private void mommon()//普通窗口服务
 
 -         {
 
 -                 client temp=bank.delClient();
 
 -                 if(temp!=null)
 
 -                 {
 
 -                         System.out.println(Thread.currentThread().getName()+"接收到客户--"+temp);
 
 -                         clientEvent(temp.getClientneed());
 
 -                 }else
 
 -                 {
 
 -                         try{Thread.sleep(1000);//没有普通用户则休息一秒
 
 -                         }catch
 
 -                         (Exception e)
 
 -                         {}
 
 -                 }
 
 -         }
 
 -         private void quick()//快速窗口服务
 
 -         {
 
 -                 clientEventPD(bank.quickdelClient());
 
 -         }
 
 -         
 
 -         private void  VIP()//vip窗口服务
 
 -         {
 
 -                 clientEventPD(bank.VIPdelClient());
 
 -         }
 
 -         private void clientEventPD(client temp) //特殊客户判断
 
 -         {
 
 -                 if(temp!=null)
 
 -                 {
 
 -                         System.out.println(Thread.currentThread().getName()+"接收到-----"+temp);
 
 -                         clientEvent(temp.getClientneed());
 
 -                 }
 
 -                 else mommon();
 
 -         }
 
 -         
 
 -         private void clientEvent(int time)//处理客户事件
 
 -         {
 
 -                 try
 
 -                 {
 
 -                         System.out.println(Thread.currentThread().getName()+"处理客户等待"+time+"秒");
 
 -                         Thread.sleep(time*1000);
 
 -                 }
 
 -                 catch(InterruptedException e){}
 
 -         }
 
 - }
 
  复制代码模拟银行:银行具备存储用户的功能,对相应等级的用户分开存储,并拥有六个窗口 import java.util.LinkedList;   public class Bank  {         private LinkedList<client> wait;         private LinkedList<client> VIPwait;         private LinkedList<client> quickwait;         private static final Bank  bank=new Bank();         private Bank()         {                 this.inio();         }         private void inio()         {                 this.wait=new LinkedList<>();//存储普通用户                 this.VIPwait=new LinkedList<>();//存储快速用户                 this.quickwait=new LinkedList<>();//存储VIP用户         }         public static Bank getBank()         {                 return bank;         }         //三个窗口取用户         synchronized client delClient()         {                         return wait.size()!=0?wait.remove():null;         }         synchronized client quickdelClient()         {                         return quickwait.size()!=0?quickwait.remove():delClient();         }         synchronized client VIPdelClient()         {                         return VIPwait.size()!=0?VIPwait.remove():delClient();         }                  synchronized void addClient(client c)//进入客户         {                 if(c.getClientrank()<4)                                 quickwait.add(c);                 else if(c.getClientrank()<10)                         wait.add(c);                 else VIPwait.add(c);                 System.out.println("---------普通用户"+wait.size()+"人"+"---------快速用户"+quickwait.size()+"人"+"----------VIP用户"+VIPwait.size()+"人");         }         void openFram()//打开六个窗口的服务         {                 new Thread(new Fram(1),"1号普通窗口").start();                 new Thread(new Fram(1)," 2号普通窗口").start();                 new Thread(new Fram(1),"  3号普通窗口").start();                 new Thread(new Fram(1),"   4号普通窗口").start();                 new Thread(new Fram(2),"     快速窗口").start();;                 new Thread(new Fram(3),"      VIP窗口").start();         }          }  
 |