biz.Bank.java

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


import entity.Account;
import entity.CreditAccount;
import entity.SavingAccount;
import exception.LoginException;
import exception.RegisterException;


public class Bank implements IBank{
// 1.当前所有的账户对象的集合,存放在数组中
Account[] as=new Account[5];

// 2.当前账户数量
int index=0;
// public void copy(){
// Account[] as2=new Account[as.length*2];
// System.arraycopy(as, 0, as2, 0, as.length);
// as=as2;
// }
// 1.用户开户,需要的参数:id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Account对象的账号,提示:用s1.equals(s2) 可以比较s1,s2两个字符串的值是否相等.账户类型是一个整数,为0的时候表示储蓄账户,为1的时候表示信用账户MMMMM
public long reg(String password,String password2,String name,String personId,int type){
Account a=null;
if(!password.equals(password2)){
throw new RegisterException("两次密码不相同!");
}else if(type==1){
a=new SavingAccount(name,password, personId);
}else if(type==0){
a=new CreditAccount(name,password,personId);
}else{
throw new RegisterException("输入有误,请选择1或0!");
}

as[index]=a;
index++;
return a.getId();  
}
// 2.用户登录,参数:id,密码 返回登录账户的账号
public long login(long id,String password){
Account a=getAccountById(id);
if(a==null){
throw new LoginException("账户为空!");

}else if(!a.getPassword().equals(password)){
throw new LoginException("密码不正确!");
}
return a.getId();
}

// 3.用户存款,参数:id,存款数额,返回void
public void deposit(long id,double money){
Account a=getAccountById(id);
a.deposit(money);
}
// 4.用户取款,参数:id,取款数额,返回void
public void withdraw(long id,double money){
Account a=getAccountById(id);
a.withdraw(money);

}
// 5.查询余额,参数:id,返回该账户的余额 double
public double selectBalance(long id){
Account a=getAccountById(id);
return a.getBalance();
}
public  Account getAccountById(long id) {

for(int i=0;i<index;i++){
if(as[i].getId()==id){
return as[i];
}
}
return null;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值