Java语言编写实现银行账号开户存款取款和转账等功能Word文件下载.docx
《Java语言编写实现银行账号开户存款取款和转账等功能Word文件下载.docx》由会员分享,可在线阅读,更多相关《Java语言编写实现银行账号开户存款取款和转账等功能Word文件下载.docx(11页珍藏版)》请在冰豆网上搜索。
![Java语言编写实现银行账号开户存款取款和转账等功能Word文件下载.docx](https://file1.bdocx.com/fileroot1/2023-1/31/8b83affb-7ec5-4eb8-b1b6-b81982889108/8b83affb-7ec5-4eb8-b1b6-b819828891081.gif)
returncardNum;
}
publicvoidsetCardNum(intcardNum){
this.cardNum=cardNum;
publicStringgetPassWord(){
returnpassWord;
publicvoidsetPassWord(StringpassWord){
this.passWord=passWord;
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
this.name=name;
publicStringgetAddress(){
returnaddress;
publicvoidsetAddress(Stringaddress){
this.address=address;
publiclonggetTelephone(){
returntelephone;
publicvoidsetTelephone(longtelephone){
this.telephone=telephone;
publicfloatgetMoney(){
returnmoney;
publicvoidsetMoney(floatmoney){
this.money=money;
}
}
2.建立测试类JunitTest文件
importstaticorg.junit.Assert.*;
importjava.text.DecimalFormat;
importorg.junit.Before;
importorg.junit.Test;
publicclassATMTest{
Scannersn=newScanner(System.in);
List<
BankAccount>
clientList=newArrayList<
();
//采用动态数组来存放用户的信息
DecimalFormatdf=newDecimalFormat("
0.00"
);
//格式化输出余额
Before
publicvoidsetUp()throwsException{
Test
publicvoidtest(){
System.out.println("
\t\t\t**********************⊙***********************"
\t\t\t**"
\t\t\t*⊙欢迎进入中国银行*"
\t\t\t*********************⊙************************"
while(true){
System.out.println("
\t\t\t请选择您要办理的手续:
"
\t\t\t\t1.开户"
\t\t\t\t2.存款"
\t\t\t\t3.取款"
\t\t\t\t4.查询余额"
\t\t\t\t5.转账"
\t\t\t\t6.退出"
\t\t\t请输入您要办理的项目"
intnum=sn.nextInt();
if(num==1){
openAccount();
}
elseif(num==2){
saveMoney();
elseif(num==3){
takeMoney();
elseif(num==4){
checkMoney();
elseif(num==5){
transferMoney();
elseif(num==6){
System.out.println("
退出"
break;
else{
请输入正确的选项!
!
}
publicclassBankAccount{
privateintcardNum;
privateStringpassWord;
privateStringname;
privateStringaddress;
privatelongtelephone;
privatedoublemoney;
publicintgetCardNum(){
returncardNum;
publicvoidsetCardNum(intcardNum){
this.cardNum=cardNum;
publicStringgetPassWord(){
returnpassWord;
publicvoidsetPassWord(StringpassWord){
this.passWord=passWord;
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
this.name=name;
publicStringgetAddress(){
returnaddress;
publicvoidsetAddress(Stringaddress){
this.address=address;
publiclonggetTelephone(){
returntelephone;
publicvoidsetTelephone(longtelephone){
this.telephone=telephone;
publicdoublegetMoney(){
returnmoney;
publicvoidsetMoney(doublemoney){
this.money=money;
publicvoidopenAccount(){//开户函数
BankAccountaccount=newBankAccount();
intcardNum=(int)(Math.random()*90000+10000);
account.setCardNum(cardNum);
系统已为您随机分配一个卡号"
+cardNum);
请为您的账户设置密码:
StringpassWord=sn.next();
account.setPassWord(passWord);
请输入您的:
Stringname=sn.next();
account.setName(name);
请输入您的地址"
Stringaddress=sn.next();
account.setAddress(address);
请输入您的联系:
longtelephone=sn.nextLong();
account.setTelephone(telephone);
if(clientList.isEmpty()){
clientList.add(account);
开户成功!
+"
您的卡号是:
+account.getCardNum());
else{
BankAccountaccount_1=checkCardNum(account.getCardNum());
//卡号应是唯一的,若已在clientList中则表示卡号重复,需要重新开户,否则可以将account对象添加到clientList中
if(account_1==null){
account.setMoney(0);
clientList.add(account);
}//end
publicvoidsaveMoney(){//存款函数
BankAccountaccount=login();
//每次操作前需要先登录
if(account==null){
账号或密码有误,登录失败!
登录成功!
请输入您的存款金额:
doublemoney=sn.nextFloat();
account.setMoney(money+account.getMoney());
Stringstr=df.format(account.getMoney());
存款成功!
您现在的卡上余额为:
+str);
publicvoidtakeMoney(){//取款函数
您输入的账号或密码有误,登录失败!
请输入您的取款金额:
if(account.getMoney()<
money){
您的卡上余额不足"
+money+"
取款失败!
account.setMoney(account.getMoney()-money);
Stringstr=df.format(account.getMoney());
publicvoidcheckMoney(){//查询余额函数
您输入的账号不存在或密码有误,登录失败!
查询余额成功!
publicvoidtransferMoney(){//转账函数
请输入你要转账的卡号:
intcardNum=sn.nextInt();
BankAccountaccount_1=checkCardNum(cardNum);
if(account_1!
=null){
您要转账的客户的为:
+account_1.getName());
请输入您的转账金额:
doublemoney=sn.nextFloat();
if(money>
account.getMoney()){
System.out.println("
转账失败!
}
else{
account.setMoney(account.getMoney()-money);
account_1.setMoney(money+account_1.getMoney());
Stringstr=df.format(account.getMoney());
转账成功!
您现在的卡上余额是:
您输入的卡号在本行不存在,转账失败!
publicBankAccountcheckCardNum(intcardNum){//查询卡号在clientList中是否存在clientList,若找到则返回其中的account对象,否则返回null
BankAccountaccount=null;
for(BankAccountaccount_1:
clientList){//遍历clientList列表
if(account_1.getCardNum()==cardNum){
account=account_1;
account=null;
returnaccount;
publicBankAccountlogin(){//登录函数如果客户输入的卡号和密码与存入clientList中找到的account对象的卡号和密码相同才表示登录成功
BankAccountaccount_1=null;
请输入您的卡号:
intcardNum=sn.nextInt();
BankAccountaccount=checkCardNum(cardNum);
请输入您的密码:
if(account!
=null&
&
account.getPassWord().equals(passWord)){
account_1=account;
account_1=null;
returnaccount_1;