BAM银行账户管理系统java类Word下载.docx
- 文档编号:19101703
- 上传时间:2023-01-03
- 格式:DOCX
- 页数:22
- 大小:139.67KB
BAM银行账户管理系统java类Word下载.docx
《BAM银行账户管理系统java类Word下载.docx》由会员分享,可在线阅读,更多相关《BAM银行账户管理系统java类Word下载.docx(22页珍藏版)》请在冰豆网上搜索。
2、本系统代码涉及到包,所以如果报名不一致就会报错,解决方法:
修改一下包名即可
3、建议把各个类写在同一个包下面,且每一个类单独写一个java文件,如下图:
4、在运行程序前,需要在项目下面新建一个account.txt(用来保存数据)文件(如上图),并在其中写入至少一个账户信息,(如下图,其中每项代表的意思,请读者参照代码内的注释),否则在初始化的时候会因为找不到账户信息,从而产生异常。
系统源码:
Account类
packagecom.qx;
//包名
/**
*账户类:
包含两种账户类型-->
1.储蓄账户2.信用账户
*/
publicabstractclassAccount{
//属性
protectedlongid;
protectedStringpassword;
protectedStringname;
protectedStringpersonId;
protectedintaccountType;
protecteddoublebalance;
//构造方法
publicAccount(){
super();
}
publicAccount(longid,Stringpassword,Stringname,StringpersonId,
intaccoutType,doublebalance){
this.id=id;
this.password=password;
this.name=name;
this.personId=personId;
this.accountType=accountType;
this.balance=balance;
//getXxx,setXxx方法
publiclonggetId(){
returnid;
publicvoidsetId(longid){
publicStringgetPassword(){
returnpassword;
publicvoidsetPassword(Stringpassword){
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
publicStringgetPersonId(){
returnpersonId;
publicvoidsetPersonId(StringpersonId){
publicintgetAccountType(){
returnaccountType;
publicvoidsetAccountType(intaccountType){
publicdoublegetBalance(){
returnbalance;
publicvoidsetBalance(doublebalance){
/**
*存款
publicvoiddeposit(doublemoney){
balance+=money;
*取款(取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类)
publicabstractvoidwithdraw(doublemoney);
}
SavingAccount类
*储蓄账户类
publicclassSavingAccountextendsAccount{
//构造函数
publicSavingAccount(){
publicSavingAccount(longid,Stringpassword,Stringname,
StringpersonId,intaccountType,doublebalance){
super(id,password,name,personId,accountType,balance);
//对父类的withdraw()实现
publicvoidwithdraw(doublemoney){
if(balance<
money){
System.out.println("
对不起,账户余额不足!
"
);
}
else
{
balance-=money;
CresitAccount类
*信用账户类,增加一个信用额度ceiling属性
publicclassCreditAccountextendsAccount{
privateintceiling;
publicCreditAccount(){
publicCreditAccount(longid,Stringpassword,Stringname,
StringpersonId,intaccountType,doublebalance,intceiling){
this.ceiling=ceiling;
publicintgetCeiling(){
returnceiling;
publicvoidsetCeiling(intceiling){
//实现父类的withdraw()
if((balance+ceiling)<
对不起,已超出您的信用额度!
Bank类
importjava.io.BufferedReader;
importjava.io.BufferedWriter;
importjava.io.File;
importjava.io.FileNotFoundException;
importjava.io.FileReader;
importjava.io.FileWriter;
importjava.io.IOException;
importjava.util.Properties;
*Bank类
*编写Bank类,属性:
1.当前所有的账户对象的集合,存放在数组中
2.当前账户数量
方法:
1.用户开户,需要的参数:
id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Account对象的账号,
提示:
用s1.equals(s2)可以比较s1,s2两个字符串的值是否相等.账户类型是一个整数,为0的时候表示储蓄账户,为1的时候表示信用账户
2.用户登录,参数:
id,密码返回登录账户的账号
3.用户存款,参数:
id,存款数额,返回void
4.用户取款,参数:
id,取款数额,返回void
5.查询余额,参数:
id,返回该账户的余额double
用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数
publicclassBank{
privateAccount[]accounts=newAccount[20];
privateintnumber;
//账户数目
privateintid=1001;
//确定银行账号从1001开始生成,即第一个账户的账号是1001
publicBank(){
accounts=newAccount[20];
//以后不足时扩容。
number=0;
BufferedReaderbufReader=null;
Propertiesprops=System.getProperties();
Stringpath=props.getProperty("
user.dir"
try{
bufReader=newBufferedReader(newFileReader(newFile(path,"
account.txt"
)));
Strings=bufReader.readLine();
while(s!
=null){
String[]str=s.split("
"
if(str[4].equals("
0"
))
{
AccountsavingAcc=newSavingAccount(Long.parseLong(str[0]),
str[1].toString(),str[2].toString(),
str[3].toString(),Integer.parseInt(str[4]),
Double.parseDouble(str[5]));
accounts[number]=savingAcc;
}
else
AccountcreditAcc=newCreditAccount(Long.parseLong(str[0]),
Double.parseDouble(str[5]),5000);
accounts[number]=creditAcc;
number++;
id++;
s=bufReader.readLine();
}
}catch(NumberFormatExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(FileNotFoundExceptione){
}catch(IOExceptione){
}finally{
try{
if(bufReader!
=null)
bufReader.close();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
//getXxx,setXxx
publicAccount[]getAccounts(){
returnaccounts;
publicvoidsetAccounts(Account[]accounts){
this.accounts=accounts;
publicintgetNumber(){
returnnumber;
publicvoidsetNumber(intnumber){
this.number=number;
publicintgetId(){
publicvoidsetId(intid){
*开户
publicAccountopenAccount(Stringpasswd1,Stringpasswd2,Stringname,
StringpersonId,inttype){
//创建一个新账户
Accountaccount=null;
//判断两次密码是否一致
if(passwd1.equals(passwd2)){
//若一致,再判断账户类型(根据type的值)
if(type==1){
//可令开始余额为10,信用额度为5000
account=newCreditAccount(id,passwd1,name,personId,type,10,5000);
else
{
account=newSavingAccount(id,passwd1,name,personId,type,10);
//将账户存入账户数组accounts[]中
//判断是否超出存储空间
if(number>
=accounts.length)
{//扩容
Account[]newAccounts=newAccount[accounts.length*2];
//copy原来的相关数据
System.arraycopy(accounts,0,newAccounts,0,accounts.length);
//将newAccounts[]赋给accounts[]
accounts=newAccounts;
accounts[number]=account;
开户成功!
!
账户信息见下"
您的卡号为:
+id+"
\n"
+"
您的密码为:
+passwd1+"
您的户名为:
+name+"
+"
您的身份证号为:
+personId+"
您的账户类型为:
+type+"
account.accountType=type;
number++;
id++;
returnaccount;
//此时开户成功
对不起!
您两次密码输入不匹配,开户失败!
returnnull;
//此时开户失败
*保存数据
publicvoidsaveAccountDate(){
BufferedWriterbufWriter=null;
Propertiesprops=System.getProperties();
Stringpath=props.getProperty("
bufWriter=newBufferedWriter(newFileWriter(newFile(path,"
for(inti=0;
i<
accounts.length;
i++)
{//若存在账户
if(accounts[i]!
{
//写入账户信息到account.txt
bufWriter.write(accounts[i].id+"
bufWriter.write(accounts[i].getPassword()+"
bufWriter.write(accounts[i].getName()+"
bufWriter.write(accounts[i].getPersonId()+"
bufWriter.write(accounts[i].getAccountType()+"
bufWriter.write(Double.toString(accounts[i].getBalance()));
bufWriter.newLine();
break;
}
bufWriter.flush();
//清空缓存中的内容
if(bufWriter!
=null){
bufWriter.close();
*登录验证
publicAccountverifyAccount(longid,Stringpassword){
for(inti=0;
{//若存在账户
if(accounts[i]!
{//验证id号和password
if(id==accounts[i].getId()&
&
password.equals(accounts[i].getPassword()))
account=accounts[i];
break;
returnaccount;
*转账验证(方法的重载)
publicAccountverifyAccount(longid){
if(id==accounts[i].getId())
*转账
publicvoidtransferAccount(Accountaccount1,Accountaccount2,doublemoney){
account1.withdraw(money);
account2.deposit(money);
publicvoiddeposit(Accountaccount,doublemoney){
account.deposit(money);
*取款
publicvoidwithdraw(Accountaccount,doublemoney){
account.withdraw(money);
ATM类
impo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BAM 银行 账户 管理 系统 java
![提示](https://static.bdocx.com/images/bang_tan.gif)