银行管理系统JAVAWord文件下载.doc
《银行管理系统JAVAWord文件下载.doc》由会员分享,可在线阅读,更多相关《银行管理系统JAVAWord文件下载.doc(17页珍藏版)》请在冰点文库上搜索。
![银行管理系统JAVAWord文件下载.doc](https://file1.bingdoc.com/fileroot1/2023-4/30/17c46957-32b0-41d6-8987-012cee48c1f0/17c46957-32b0-41d6-8987-012cee48c1f01.gif)
+personId+"
+email+"
+balance;
/**无参构造体*/
publicAccount(){
/**有参构造体,用于初始化对象的必要属性*/
publicAccount(longid,Stringpassword,Stringname,StringpersonId,
Stringemail,doublebalance)
{
this.setId(id);
this.setPassword(password);
this.setName(name);
this.setPersonId(personId);
this.setEmail(email);
this.setBalance(balance);
/**存款方法*/
publicvoiddeposit(doublemoney){
balance+=money;
/**取款方法,抽象类,行为不确定,有储蓄账户和信用账户之分
*@throwsBalanceNotEnoughException*/
publicabstractvoidwithdraw(doublemoney)throwsBalanceNotEnoughException;
/**属性的封装*/
publicvoidsetId(longid){
this.id=id;
publiclonggetId(){
returnid;
publicvoidsetPassword(Stringpassword){
this.password=password;
publicStringgetPassword(){
returnpassword;
publicvoidsetName(Stringname){
this.name=name;
publicStringgetName(){
returnname;
publicvoidsetPersonId(StringpersonId){
this.personId=personId;
publicStringgetPersonId(){
returnpersonId;
publicvoidsetEmail(Stringemail){
this.email=email;
publicStringgetEmail(){
returnemail;
publicvoidsetBalance(doublebalance){
this.balance=balance;
publicdoublegetBalance(){
returnbalance;
}
2)ATM.java类
importjava.io.*;
publicclassATM{
privateBankbank;
publicATM(){
/*初始化Bank类,此时调用Bank的构造函数,其中默认的两个测试用户的信息被添加到Account类中*/
bank=newBank();
publicstaticvoidmain(String[]args){
ATMatm=newATM();
atm.mainMenu();
privatevoidmainMenu(){
booleanoutflag=true;
do{
System.out.println("
ATM服务系统"
);
****************"
1.登录"
2.开户"
0.退出"
System.out.print("
请选择操作:
Scannerscanner=newScanner(System.in);
StringfirstChoice;
do{
firstChoice=scanner.next();
if(firstChoice.matches("
^[0-2]$"
)){
break;
}else
System.out.println("
选择输入错误!
}while(true);
booleanrt=true;
out:
do{
switch(Integer.parseInt(firstChoice)){
case1:
/*进入登录界面或登录成功界面*/
secondMenu();
breakout;
case2:
/*开户,捕捉createAccount方法抛出的所有异常*/
try{
bank.createAccount();
}catch(RegisterExceptione){
System.out.println(e.toString());
}
rt=false;
case0:
outflag=false;
default:
}
}while(rt);
}while(outflag);
System.out.println("
谢谢您的使用!
/**登录成功后的二级菜单*/
privatevoidsecondMenu(){
Scannerscanner=newScanner(System.in);
Accountaccount=null;
out:
do
try{
/*输入卡号,输入exit可以直接退出系统*/
System.out.print("
输入卡号:
StringcardNo0;
longcardNo;
out1:
cardNo0=scanner.next();
if(cardNo0.equals("
exit"
)||cardNo0.equals("
EXIT"
breakout;
}elseif(cardNo0.matches("
^[0-9_]+$"
cardNo=Long.parseLong(cardNo0);
breakout1;
}else
System.out.println("
请输入数字类型的ID!
}while(true);
/*输入密码,输入exit可以直接退出系统*/
密码:
Stringpassword=scanner.next();
if(password.equals("
)||password.equals("
account=bank.login(cardNo,password);
breakout;
}catch(LoginExceptione){
System.out.println(e.toString());
}
while(true);
if(account!
=null){
System.out.println("
ATM操作界面"
1.存款操作"
2.取款操作"
3.查询余额"
4.设置透支额度"
5.统计银行总余额"
6.查询本人信息"
0.退出"
scanner=newScanner(System.in);
Stringsc;
do{
sc=scanner.next();
if(sc.matches("
^[0-6]+$"
break;
选择操作输入错误!
switch(Integer.parseInt(sc)){
/*存款*/
/*最外层的循环用来询问用户是否继续。
*/
do{
/*金额必须为数字类型,不能存取低于一元金额*/
do{
System.out.println("
请输入存款金额:
Stringmoney=scanner.next();
if(money.matches("
bank
.deposit(account,Double
.parseDouble(money));
break;
}else
System.out.println("
金额必须为数字!
}while(true);
存款结束!
………………继续存款(Y)/结束存款(输入任意字符)"
Scanners=newScanner(System.in);
Stringchoice=s.next();
if(choice.equals("
Y"
)||choice.equals("
y"
))
continue;
else
break;
}while(true);
/*取款*/
请输入取款金额:
try{
bank.withdraw(account,Double
.parseDouble(money));
}catch(BalanceNotEnoughExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
金额必须是数字类型!
取款结束!
………………继续取款(Y)/结束取款(输入任意字符)"
case3:
/*查看余额*/
bank.showBalance(account);
case4:
/*设置透支额度*/
bank.setCeiling(account);
case5:
/*统计银行总余额,调用Bank类中的totalBalance方法*/
bank.totalBalance(account);
case6:
/*Account类中覆盖的toString方法使用*/
System.out.println(account.toString());
/*退出的时候调用写入的方法,把更新的用户信息覆盖掉原来Accounts,txt中旧的数据*/
bank.writeIntoTxt();
3)Bank.java类
publicclassBank{
List<
Account>
list;
publicBank(){
list=newLinkedList<
();
longid;
Stringpassword,name,personId,email;
doublebalance,ceiling;
Propertiesp=System.getProperties();
Stringworkpath=p.getProperty("
user.dir"
BufferedReaderbr=null;
try{
FilesourceFile=newFile(workpath,"
Accounts.txt"
br=newBufferedReader(newFileReader(sourceFile));
Stringstr=br.readLine();
StringsingleInfo[]=newString[10];
while(str!
/*以分号为分隔符,把字符串分为字段数组存放*/
singleInfo=str.split("
if(singleInfo.length==6){
id=Long.parseLong(singleInfo[0]);
password=singleInfo[1];
name=singleInfo[2];
personId=singleInfo[3];
email=singleInfo[4];
balance=Double.parseDouble(singleInfo[5]);
Accountobj=newSavingAccount(id,password,name,
personId,email,balance);
list.add(obj);
/*第line行的长度是7,说明有ceiling字段,是信用卡账户*/
if(singleInfo.length==7){
ceiling=Double.parseDouble(singleInfo[6]);
Accountobj=newCreditAccount(id,password,name,
personId,email,balance,ceiling);
str=br.readLine();
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
}finally{
if(br!
=null)
br.close();
}catch(IOExceptione){
e.printStackTrace();
/**登录功能,登录成功返回Account类型,不成功account引用为空*/
publicAccountlogin(longcardNo,Stringpassword)throwsLoginException{
intl=list.size();
inti=0;
for(i=0;
i<
list.size();
i++){
if(list.get(i).getId()==cardNo
&
&
list.get(i).getPassword().equals(password)){
/*如果登录成功,返回account引用指向所在的账户对象,账户信息都在该对象中存放*/
account=list.get(i);
break;
if(i==l)
thrownewLoginException("
卡号或密码错误!
returnaccount;
/**
*存款功能,方法在deposit中定义,ATM无论传来CreditAccount还是SavingAccount的对象,
*都只有父类Account实现的方法deposit方法可供调用,此处不存在动态实现多态
*/
publicvoiddeposit(Accountaccount,doublemoney){
account.deposit(money);
*取款,体现出动态多态,如果在ATM中传来account引用指向CreditAccount类的对象则调用其中的withdraw方法,
*指向SavingAccount的对象则调用SavingAccount中实现的方法,不确定性,在运行过程中动态的选择。
public