class Account{
	double balance;
	public synchronized void deposit(double money){
		balance = balance + money;
		System.out.println("存入"+money+"元，账户余额"+balance+"元。");
		try{
			Thread.sleep(1000);
		}catch(InterruptedException e){
		    System.out.println(e);
		}
		notifyAll();
	}
	public synchronized void withdraw(double money){
		while(balance<money){
			System.out.println("账户余额不足，等待存款。");
			try{
				wait();
			}catch(InterruptedException e){
				System.out.println(e);
			}
		}
		balance = balance-money;
		System.out.println("取出"+money+"元，账户余额"+balance+"元。");
	}
}

public class SynchroTest implements Runnable{
	Thread liLei,hanMeiMei;
	Account account;
	SynchroTest(){
		liLei = new Thread(this);
		hanMeiMei = new Thread(this);
		account = new Account();
	}
	public void run(){
		if(Thread.currentThread()==liLei){
			for(int i = 1;i<=3;i++){
				System.out.println("李雷挣钱，将工资悉数存入家庭银行......");
				account.deposit(1000);
				try{
			        Thread.sleep(3000);
		        }catch(InterruptedException e){
		        	System.out.println(e);
	          	}
			}
		}else if(Thread.currentThread()==hanMeiMei){
			for(int i = 1;i<=3;i++){
				System.out.println("韩梅梅把握家中的开支，从家庭银行取钱......");
				account.withdraw(800);
			}
		}
	}
}

class TestMain{
	public static void main(String[] args){
		SynchroTest synchro = new SynchroTest();
		synchro.liLei.start();
		synchro.hanMeiMei.start();
	}
}