黑马程序员-银行业务调度系统(自己写的)目前还有异常,不知道怎么处理?

----------- android培训java培训、java学习型技术博客、期待与您交流! ------------



public class Bank
{
	public static void main(String[] args)
	{
		new Thread(new Number(1000)).start();//开启调用随机生成人员的线程
		for(int i = 1 ;i<=10;i++)//开启10个窗口的线程
		{
			new Thread(new Monitor(i)).start();
		}
	}

}

class Monitor implements Runnable
{
	public int y1;
	public Monitor(int y1)
	{
		this.y1=y1;
	}
	public synchronized void sop()
	{
		if (Number.al1.size() > 0)
		{
			Number.al1.remove(0);//移除集合的第一个元素,表示处理好一个客户
			System.out.println("第" + y1 + "窗口处理了一个普通客户");
			try
			{
				Thread.sleep((new Random().nextInt(10)+1)*100);//处理一个客户用的时间随机取值
			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	public void run()
	{
		while (true)
		{
			if (y1 >= 1 && y1 <= 6)
			{
				sop();
				
			} else if (y1 == 7)
			{
				if (Number.al2.size() > 0)
				{
					Number.al2.remove(0);
					System.out.println("第" + y1 + "窗口处理了一个VIP客户");
					try
					{
						Thread.sleep((new Random().nextInt(10)+1)*100);
						//处理一个客户用的时间随机取值
					} catch (Exception e)
					{
						e.printStackTrace();
					}
				} else 
				{
					sop();
				}
			} else
			{
				if (Number.al3.size() > 0)
				{
					Number.al3.remove(0);
					System.out.println("第" + y1 + "窗口处理了一个快速客户");
					try
					{
						Thread.sleep((new Random().nextInt(10)+1)*100);
						//处理一个客户用的时间随机取值
					} catch (Exception e)
					{
						e.printStackTrace();
					}
				} else 
				{
					sop();
				}
			}
			try
			{
				Thread.sleep((new Random().nextInt(10)+1)*100);
			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}
	}

}



class Number implements Runnable
{
	public int x;
	public int o1;
	public int o2=1;
	public static int uuu=1;
	public static ArrayList<String> al1,al2,al3;
	public Number(int o1)//构造函数用于生成3个集合保存3种客户
	{
		this.o1=o1;
		al1 = new ArrayList<String>();
		al2 = new ArrayList<String>();
		al3 = new ArrayList<String>();
	}
	
	public void run()
	{
		Randomgeneration();
	}
	public void Randomgeneration()
	{
		while(o2<=o1)
		{
			x = (int) (Math.random() * 10 + 1);//随机生成1-10用于判断来的人员是什么客户
			Judge(x);
			try
			{
				Thread.sleep((new Random().nextInt(10)+1)*100);
				//这个时间要注意下,随机生成人员来的时间
			} catch (Exception e)
			{
				e.printStackTrace();
			}
			o2++;//人员截至条件
		}
	}
	public void Judge(int y)
	{
		if(y>=1&&y<=6)
		{
			al1.add("people");
			System.out.println("第"+uuu+++"号来了一个普通客户");
			//在普通客户的数组进行添加1个人员
		}else if(y==7)
		{
			al2.add("people");
			System.out.println("第"+uuu+++"号来了一个VIP客户");
			//在VIP客户的数组进行添加1个人员
		}else
		{
			al3.add("people");
			System.out.println("第"+uuu+++"号来了一个快速客户");
			//在快速客户的数组进行添加1个人员
		}
	}
}



 




----------------------- android培训java培训、java学习型技术博客、期待与您交流! ----------------------

详情请查看:http://edu.csdn.net/heima

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值