⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank.java

📁 纯JAVA代码实现的银行柜员机的基本功能
💻 JAVA
字号:
package biz;            
import dao.AccountDao;
import dao.impl.AccountFileDao;
import Exception.BalanceNotEnoughException;
import Exception.LoginException;
import Exception.RegisterException;
import entity.*;


public class Bank implements IBank{  
	AccountDao dao=new AccountFileDao();
  /*  private Account[]  accounts=new Account[10];
    private int index=0;
    private void expand(){  
    	Account[]  as=new Account[accounts.length*2];
    	System.arraycopy(accounts,0,as,0,accounts.length);
    	accounts=as;
    }   */ 
    public long regist(String name,String password,String againPassword,String personId,int type)throws RegisterException{
         if(password.equals(againPassword)){  
         	Account a=null;
         	 if(type==0){
         	 	a=new SavingAccount(name,password,personId); 
         	}
         	if(type==1){   
         		a=new CreditAccount(name,password,personId);
         	} 
         	dao.saveAccount(a) ;  
         	return a.getId();
        }else{   
        	throw new RegisterException("两次密码不一致");
        	//System.out.println("对不起,密码错误!");
        	//return -1;
        }
    } 
    public long login(long id,String password) throws LoginException{      
    	// 根据id查找帐户,获取该帐户的password  
    	Account a=queryById(id);
    	if(a==null){  
    		throw new LoginException("帐户不存在");
    	//	System.out.println("对不起,帐户不存在");
    	//	return -1;
    	}        
    	String password1=a.getPassword();
    	// 判断两个password是否相等  
    	if(password1.equals(password)){ 
    		return id;
    	}else
    	throw new LoginException("密码错误");
    	//System.out.println("对不起,密码错误");
    	//return -1;
    }      
    public Account deposit(long id,double money){  
    	Account a=dao.findAccountById(id);
		a.deposit(money);
		dao.saveAccount(a);
		return a;
    }  
    public Account withdraw(long id,double money) throws BalanceNotEnoughException{  
    	Account a=dao.findAccountById(id);
		a.withdraw(money);
		dao.saveAccount(a);
		return a;
		 
    }
    public double queryBalance(long id){ 
    	//  根据id查找帐户   
    	Account a=queryById(id);
    	 if(a==null){     
    		System.out.println("对不起,帐户不存在");
    		return -1;
    	}else{         
    		return a.getBalance();
    	} 
    }   
    private Account queryById(long id){   
    	return dao.findAccountById(id) ;  
    }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -