1、BAM银行账户管理系统(ATM管理系统)本系统采用JAVA语言并在eclipse环境下编写测试完成,涉及类的概念,以及面向对象的几大特性(继承,封装,多态,抽象),也有异常处理机制,基本可以满足大多数BAM系统的相关实现,且代码内标注大量注释,读者可以很轻松地理解相关逻辑,大家可以开心参考。系统简介:1、JAVA类的面相对象的应用,拥有异常处理机制,不会因为输入错误而导致程序崩溃2、主要有5个类,即Account(账户类)SaveAccount(储蓄账户类):不能透支CreditAccount(信用账户类):可以透支Bank(银行类)ATM(ATM类) 类的具体属性级行为见代码 3、各个类之间
2、的相互关系,涉及继承、封装、多态、抽象,在多态中又涉及重载和重 写,请读者注意相关联系(关注注释) 4、可以实现数据保存功能,数据将保存在文件中(即当你注册了一个账户,下次再登 陆系统时,可以实现与上次最后的操作相衔接) 5、账户号自动生成,比较符合现实 6、主要功能有:1.开户 2.查询账户余额 3.存款 4.取款 5.转账(一个账户到另一个账户)等 7、运行时界面简示1.初始界面(账户登录) 2.账户登录后界面注意事项:1、本系统采用的编程环境是JDK1.7,jer7。所以,运行代码需要保持电脑上所装的JDK为1.7以上版本,如有报错,只需换个高一点的版本即可。注意:第一次装JDK,要配置
3、环境变量(请查阅相关资料,比较简单)2、本系统代码涉及到包,所以如果报名不一致就会报错,解决方法:修改一下包名即可3、建议把各个类写在同一个包下面,且每一个类单独写一个java文件,如下图:4、在运行程序前,需要在项目下面新建一个account.txt(用来保存数据)文件(如上图),并在其中写入至少一个账户信息,(如下图,其中每项代表的意思,请读者参照代码内的注释),否则在初始化的时候会因为找不到账户信息,从而产生异常。系统源码:Account类package com.qx;/包名/* * 账户类:包含两种账户类型-1.储蓄账户 2.信用账户 */public abstract class A
4、ccount /属性protected long id;protected String password;protected String name;protected String personId;protected int accountType;protected double balance;/构造方法public Account()super();public Account(long id, String password, String name, String personId,int accoutType,double balance) super();this.id =
5、 id;this.password = password;this.name = name;this.personId = personId;this.accountType = accountType;this.balance = balance;/getXxx,setXxx方法public long getId() return id;public void setId(long id) this.id = id;public String getPassword() return password;public void setPassword(String password) this
6、.password = password;public String getName() return name;public void setName(String name) this.name = name;public String getPersonId() return personId;public void setPersonId(String personId) this.personId = personId;public int getAccountType() return accountType;public void setAccountType(int accou
7、ntType) this.accountType = accountType;public double getBalance() return balance;public void setBalance(double balance) this.balance = balance;/* * 存款 */public void deposit(double money)balance += money;/* * 取款(取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类) */public abstract void withdraw(double money);Sav
8、ingAccount类package com.qx;/* * 储蓄账户类 */public class SavingAccount extends Account /构造函数public SavingAccount() super();public SavingAccount(long id, String password, String name, String personId,int accountType, double balance) super(id, password, name, personId, accountType, balance);/对父类的withdraw()
9、实现public void withdraw(double money)if(balance money)System.out.println(对不起,账户余额不足!);elsebalance -= money;CresitAccount类package com.qx;/* * 信用账户类,增加一个信用额度ceiling属性 */public class CreditAccount extends Accountprivate int ceiling;/构造函数public CreditAccount()super();public CreditAccount(long id, String
10、password, String name,String personId,int accountType, double balance, int ceiling)super(id, password, name, personId, accountType, balance);this.ceiling = ceiling;/getXxx,setXxx方法public int getCeiling() return ceiling;public void setCeiling(int ceiling) this.ceiling = ceiling;/实现父类的withdraw()public
11、 void withdraw(double money)if(balance + ceiling) = accounts.length)/扩容Account newAccounts = new Accountaccounts.length*2;/copy原来的相关数据System.arraycopy(accounts, 0, newAccounts, 0, accounts.length);/将newAccounts赋给accountsaccounts = newAccounts;accountsnumber = account;elseaccountsnumber = account;Sys
12、tem.out.println(开户成功!账户信息见下);System.out.println(您的卡号为:+id+n+您的密码为:+passwd1+n+您的户名为:+name+n+您的身份证号为:+personId+n+您的账户类型为:+type+n);account.accountType = type;number+;id+;return account;/此时开户成功elseSystem.out.println(对不起!您两次密码输入不匹配,开户失败!);return null;/此时开户失败/* * 保存数据 */public void saveAccountDate()Buffer
13、edWriter bufWriter=null;try Properties props=System.getProperties();String path=props.getProperty(user.dir);bufWriter=new BufferedWriter(new FileWriter(new File(path,account.txt);for(int i = 0;i accounts.length;i+)/若存在账户if(accountsi != null)/写入账户信息到account.txtbufWriter.write(accountsi.id+,);bufWrite
14、r.write(accountsi.getPassword()+,);bufWriter.write(accountsi.getName()+,);bufWriter.write(accountsi.getPersonId()+,);bufWriter.write(accountsi.getAccountType()+,);bufWriter.write(Double.toString(accountsi.getBalance();bufWriter.newLine();elsebreak;bufWriter.flush();/清空缓存中的内容 catch (IOException e) /
15、TODO Auto-generated catch blocke.printStackTrace();finallytry if(bufWriter!=null)bufWriter.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/* * 登录验证 */public Account verifyAccount(long id, String password)Account account = null;for(int i = 0;i accounts.length;i+)/
16、若存在账户if(accountsi != null)/验证id号和passwordif(id = accountsi.getId() & password.equals(accountsi.getPassword()account = accountsi;break;elsebreak;return account;/* * 转账验证(方法的重载) */public Account verifyAccount(long id)Account account = null;for(int i = 0;i accounts.length;i+)/若存在账户if(accountsi != null)
17、/验证id号和passwordif(id = accountsi.getId()account = accountsi;break;elsebreak;return account;/* * 转账 */public void transferAccount(Account account1, Account account2, double money)account1.withdraw(money);account2.deposit(money);/* * 存款 */public void deposit(Account account, double money)account.deposit(money);/* * 取款 */public void withdraw(Account account, double money)account.withdraw(money);ATM类package com.qx;impo