本系统采用JAVA语言并在eclipse环境下编写测试完成,涉及类的概念,以及面向对象的几大特性<继承,封装,多态,抽象),也有异常处理机制,采用集合<更好)存储账户数据,基本可以满足大多数BAM系统的相关实现,且代码内标注大量注释,读者可以很轻松地理解相关逻辑,大家可以开心参考。
系统简介:
特点:
采用窗口界面风格,而不是传统的命令行、控制台运作模式
1、JAVA类的面相对象的应用,拥有异常处理机制,不会因为输入错误而导致程序崩溃
2、主要有7个类,即①Account<账户类)
②SaveAccount<储蓄账户类):
不能透支
③CreditAccount<信用账户类):
可以透支
④Bank<银行类)
⑤ATMOpenAccountFrame<开户窗口页面)
⑥ATMLoginFrame<登录窗口页面)
⑦ATMMainFrame<操作窗口页面)
带有完善的相关信息提示弹出窗口见下面截图
类的具体属性级行为见代码
3、各个类之间的相互关系,涉及继承、封装、多态、抽象,在多态中又涉及重载和重
写,请读者注意相关联系<关注注释)
4、可以实现数据保存功能,数据将保存在文件中<即当你注册了一个账户,下次再登
陆系统时,可以实现与上次最后的操作相衔接)
5、账户号自动生成,比较符合现实
6、主要功能有:
1.开户
2.查询账户余额
3.存款
4.取款
5.转账<一个账户到另一个账户)等……
7、运行时界面简示
1.初始界面<账户登录)
2.账户登录后界面
3.相关信息提示一览<只列举一部分)
1、查询:
2、存款:
3、取款:
4、转账:
4、用户开户界面:
注意事项:
1、本系统采用的编程环境是JDK1.7,jer7。
所以,运行代码需要保持电脑上所装的JDK为1.7以上版本,如有报错,只需换个高一点的版本即可。
注意:
第一次装JDK,要配置环境变量<请查阅相关资料,比较简单)b5E2RGbCAP
2、本系统代码涉及到包,所以如果报名不一致就会报错,解决方法:
修改一下包名即可
3、建议把各个类写在同一个包下面,且每一个类单独写一个java文件,如下图:
4、在运行程序前,需要在工程下面新建一个account.txt<用来保存数据)文件<如上图),并在其中写入至少一个账户信息,<如下图,其中每项代表的意思,请读者参照代码内的注释),否则在初始化的时候会因为找不到账户信息,从而产生异常。
p1EanqFDPw
系统源码:
Account类
packagecom.qx。
importjavax.swing.JOptionPane。
/**
*账户类:
包含两种账户类型-->1.储蓄账户2.信用账户
*/
publicabstractclassAccount{
//属性
protectedlongid。
protectedStringpassword。
protectedStringname。
protectedStringpersonId。
protectedStringaccountType。
protecteddoublebalance。
//构造方法
publicAccount(>{
super(>。
}
publicAccount(longid,Stringpassword,Stringname,StringpersonId,DXDiTa9E3d
Stringtype,doublebalance>{
super(>。
this.id=id。
this.password=password。
this.name=name。
this.personId=personId。
this.accountType=type。
this.balance=balance。
}
//getXxx,setXxx方法
publiclonggetId(>{
returnid。
}
publicvoidsetId(longid>{
this.id=id。
}
publicStringgetPassword(>{
returnpassword。
}
publicvoidsetPassword(Stringpassword>{
this.password=password。
}
publicStringgetName(>{
returnname。
}
publicvoidsetName(Stringname>{
this.name=name。
}
publicStringgetPersonId(>{
returnpersonId。
}
publicvoidsetPersonId(StringpersonId>{
this.personId=personId。
}
publicStringgetAccountType(>{
returnaccountType。
}
publicvoidsetAccountType(StringaccountType>{
this.accountType=accountType。
}
publicdoublegetBalance(>{
returnbalance。
}
publicvoidsetBalance(doublebalance>{
this.balance=balance。
}
/**
*存款
*/
publicvoiddeposit(doublemoney>{
balance+=money。
}
/**
*取款<取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类)
*/
publicabstractvoidwithdraw(doublemoney>。
}
SavingAccount类
packagecom.qx。
importjavax.swing.JOptionPane。
/**
*储蓄账户类
*/
publicclassSavingAccountextendsAccount{
//构造函数
publicSavingAccount(>{
super(>。
}
publicSavingAccount(longid,Stringpassword,Stringname,RTCrpUDGiT
StringpersonId,StringaccountType,doublebalance>{5PCzVD7HxA
super(id,password,name,personId,accountType,balance>。
jLBHrnAILg
}
//对父类的withdraw(>实现
publicvoidwithdraw(doublemoney>{
if(balance{
/*System.out.println("对不起,账户余额不足!
">。
*/
JOptionPane.showMessageDialog(null,"对不起,账户余额不足!
",
"信息提示",JOptionPane.ERROR_MESSAGE>。
}
else
{
balance-=money。
}
}
}
CresitAccount类
packagecom.qx。
importjavax.swing.JOptionPane。
/**
*信用账户类,增加一个信用额度ceiling属性
*/
publicclassCreditAccountextendsAccount{
privateintceiling。
//构造函数
publicCreditAccount(>{
super(>。
}
publicCreditAccount(longid,Stringpassword,Stringname,xHAQX74J0X
StringpersonId,StringaccountType,doublebalance,intceiling>{LDAYtRyKfE
super(id,password,name,personId,accountType,balance>。
Zzz6ZB2Ltk
this.ceiling=ceiling。
}
//getXxx,setXxx方法
publicintgetCeiling(>{
returnceiling。
}
publicvoidsetCeiling(intceiling>{
this.ceiling=ceiling。
}
//实现父类的withdraw(>
publicvoidwithdraw(doublemoney>{
if((balance+ceiling>{
/*System.out.println("对不起,已超出您的信用额度!
">。
*/
JOptionPane.showMessageDialog(null,"对不起,已超出您的信用额度!
",dvzfvkwMI1
"信息提示",JOptionPane.ERROR_MESSAGE>。
}
else
{
balance-=money。
}
}
}
Bank类
packagecom.qx。
importjava.io.BufferedReader。
importjava.io.BufferedWriter。
importjava.io.File。
importjava.io.FileNotFoundException。
importjava.io.FileReader。
importjava.io.FileWriter。
importjava.io.IOException。
importjava.util.ArrayList。
importjava.util.Iterator。
importjava.util.List。
importjava.util.Properties。
importjavax.swing.JOptionPane。
/**
*Bank类
*编写Bank类,属性:
1.当前所有的账户对象的集合,存放在数组中
2.当前账户数量
方法:
1.用户开户,需要的参数:
id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Account对象的账号,rqyn14ZNXI
提示:
用s1.equals(s2>可以比较s1,s2两个字符串的值是否相等.账户类型是一个整数,为0的时候表示储蓄账户,为1的时候表示信用账户EmxvxOtOco
2.用户登录,参数:
id,密码返回登录账户的账号
3.用户存款,参数:
id,存款数额,返回void
4.用户取款,参数:
id,取款数额,返回void
5.查询余额,参数:
id,返回该账户的余额double
用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数
*/
publicclassBank{
/*privateAccount[]accounts=newAccount[20]。
*/
privateListaccountsList。
privateintnumber。
//账户数目
privateintid=1001。
//确定银行账号从1001开始生成,即第一个账户的账号是1001SixE2yXPq5
//构造函数
publicBank(>{
accountsList=newArrayList(>。
number=0。
BufferedReaderbufReader=null。
Propertiesprops=System.getProperties(>。
Stringpath=props.getProperty("user.dir">。
try{
bufReader=newBufferedReader(newFileReader(newFile(path,"account.txt">>>。
6ewMyirQFL
Strings=bufReader.readLine(>。
while(s!
=null>{
String[]str=s.split(",">。
if(str[4].equals("0">>
{
AccountsavingAcc=newSavingAccount(Long.parseLong(str[0]>,kavU42VRUs
str[1].toString(>,str[2].toString(>,
str[3].toString(>,str[4].toString(>,
Double.parseDouble(str[5]>>。
accountsList.add(savingAcc>。
}
else
{
AccountcreditAcc=newCreditAccount(Long.parseLong(str[0]>,y6v3ALoS89
str[1].toString(>,str[2].toString(>,
str[3].toString(>,str[4].toString(>,
Double.parseDouble(str[5]>,5000>。
accountsList.add(creditAcc>。
}
number++。
id++。
s=bufReader.readLine(>。
}
}catch(NumberFormatExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}catch(FileNotFoundExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}catch(IOExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}finally{
try{
if(bufReader!
=null>
{
bufReader.close(>。
}
}catch(IOExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}
}
}
//getXxx,setXxx
publicListgetAccounts(>{
returnaccountsList。
}
publicvoidsetAccounts(Listaccounts>{
this.accountsList=accounts。
}
publicintgetNumber(>{
returnnumber。
}
publicvoidsetNumber(intnumber>{
this.number=number。
}
publicintgetId(>{
returnid。
}
publicvoidsetId(intid>{
this.id=id。
}
/**
*开户
*/
publicAccountopenAccount(Stringpasswd1,Stringpasswd2,Stringname,M2ub6vSTnP
StringpersonId,Stringtype>{
//创建一个新账户
Accountaccount=null。
//判断两次密码是否一致
if(passwd1.equals(passwd2>>{
//若一致,再判断账户类型<根据type的值)
if(type.equals("1">>{
//可令开始余额为10,信用额度为5000
account=newCreditAccount(id,passwd1,name,personId,type,10,5000>。
0YujCfmUCw
}
else
{
account=newSavingAccount(id,passwd1,name,personId,type,10>。
eUts8ZQVRd
}
//将账户存入账户集合accountsList中
accountsList.add(account>。
JOptionPane.showMessageDialog(null,"开户成功!
!
!
","信息提示",sQsAEJkW5T
JOptionPane.INFORMATION_MESSAGE>。
JOptionPane.showMessageDialog(null,"您的卡号为:
"+id+"\n"+GMsIasNXkA
"您的密码为:
"+passwd1+"\n"+"您的户名为:
"+name+"\n"+
"您的身份证号为:
"+personId+"\n"+"您的账户类型为:
"+type+"\n","信息提示",TIrRGchYzg
JOptionPane.INFORMATION_MESSAGE>。
account.accountType=type。
number++。
id++。
returnaccount。
//此时开户成功
}
else
{
JOptionPane.showMessageDialog(null,"对不起!
您两次密码输入不匹配,开户失败!
!
!
",7EqZcWLZNX
"信息提示",JOptionPane.ERROR_MESSAGE>。
returnnull。
//此时开户失败
}
}
/**
*保存数据
*/
publicvoidsaveAccountDate(>{
BufferedWriterbufWriter=null。
try{
Propertiesprops=System.getProperties(>。
Stringpath=props.getProperty("user.dir">。
Strings=null。
bufWriter=newBufferedWriter(newFileWriter(newFile(path,"account.txt">>>。
lzq7IGf02E
for(Iteratoriterator=accountsList.iterator(>。
iterator.hasNext(>。
>zvpgeqJ1hk
{//若存在账户
Accountacc=(Account>iterator.next(>。
//写入账户信息到account.txt
bufWriter.write(acc.id+",">。
bufWriter.write(acc.getPassword(>+",">。
bufWriter.write(acc.getName(>+",">。
bufWriter.write(acc.getPersonId(>+",">。
bufWriter.write(acc.getAccountType(>+",">。
bufWriter.write(Double.toString(acc.getBalance(>>>。
NrpoJac3v1
bufWriter.newLine(>。
}
bufWriter.flush(>。
//清空缓存中的内容
}catch(IOExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}finally{
try{
if(bufWriter!
=null>{
bufWriter.close(>。
}
}catch(IOExceptione>{
//TODOAuto-generatedcatchblock
e.printStackTrace(>。
}
}
}
/**
*登录验证
*/
publicAccountverifyAccount(longid,Stringpassword>{1nowfTG4KI
Accountaccount=null。
Accountacc=null。
for(Iteratoriterator=accountsList.iterator(>。
iterator.hasNext(>。
>fjnFLDa5Zo
{//若存在账户
acc=(Account>iterator.next(>。
if(acc!
=null>{
if(id==acc.getId(>&&password.equals(acc.getPassword(>>>{tfnNhnE6e5
account=acc。
break。
}
}
else
{
break。
}
}
returnaccount。
}
/**
*转账验证<方法的重载)
*/
publicAccountverifyAccount(long