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 Account /属性prote
4、cted 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 = id;this.passwo
5、rd = 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.password = pas
6、sword;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 accountType) this.ac
7、countType = 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);SavingAccount类packa
8、ge 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()实现public void wit
9、hdraw(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 password, String
10、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 void withdraw(dou
11、ble 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;System.out.println(开户成
12、功!账户信息见下);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()BufferedWriter bufWriter=null;
13、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+,);bufWriter.write(accountsi.getPas
14、sword()+,);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) / TODO Auto-generated catch
15、 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+)/若存在账户if(accountsi != null
16、)/验证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)/验证id号和passwordif(id = acc
17、ountsi.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
18、 void withdraw(Account account, double money)account.withdraw(money);ATM类package com.qx;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.util.Properties;import java.util.Scanner;/* * ATM类,提供用户界面操作 */public
19、 class ATM /属性private Bank bank;/结构函数public ATM() bank = new Bank();/main方法public static void main(String args)ATM atm = new ATM();/实例化ATMBank bank = atm.bank;/标号,判定是否退出一级菜单boolean firstFlag = true;while(firstFlag)/一级菜单System.out.println(*欢迎使用XXX银行模拟ATM系统,请按以下步骤操作*);System.out.println( *1.用已经有账户登录);
20、System.out.println( *2.没有账户,开户);System.out.println( *3.退出);Scanner scanner = new Scanner(System.in);System.out.print(请选择:);try int choice1 = scanner.nextInt();switch(choice1)case 1:scanner = new Scanner(System.in);System.out.print(请输入银行卡号:);long id = scanner.nextInt();scanner = new Scanner(System.in
21、);System.out.print(请输入银行密码:);String password = scanner.next();Account account = bank.verifyAccount(id, password);if(account != null)/标号,判定是否退出二级菜单boolean secondFlag = true;while(secondFlag)/二级菜单System.out.println(*欢迎使用XXX银行模拟ATM系统,请按以下步骤操作*);System.out.println( *1.查询账户余额);System.out.println( *2.存款);
22、System.out.println( *3.取款);System.out.println( *4.转账);System.out.println( *5.退卡);scanner = new Scanner(System.in);System.out.print(请选择:);try int choice2 = scanner.nextInt();switch(choice2)case 1:System.out.println(您账户目前余额为:+account.getBalance();break;case 2:scanner = new Scanner(System.in);System.ou
23、t.print(请输入您存款金额:);double money1 = scanner.nextDouble();bank.deposit(account, money1);break;case 3:scanner = new Scanner(System.in);System.out.print(请输入您取款金额:);double money2 = scanner.nextDouble();bank.withdraw(account, money2);break;case 4:scanner = new Scanner(System.in);System.out.print(请输入您要转入账户
24、卡号:);long id2 = scanner.nextLong();Account account2 = bank.verifyAccount(id2);if(account2 != null)scanner = new Scanner(System.in);System.out.print(请输入您要转入账户金额:);double money = scanner.nextLong();if(money = account.balance)bank.transferAccount(account, account2, money);System.out.println(转账成功!);else
25、System.out.println(抱歉,您账户没有足够金额!请查看后重新选择输入!);elseSystem.out.println(抱歉,没有找到您要转入账户信息!请查对后重新选择输入!);break;case 5:secondFlag = false;break;default:System.out.println(没有该选项,请重新选择!);break; catch (Exception e) System.out.println(选择输入不正当,请重新选择!);elseSystem.out.println(没有此账户,请先开户!);break;case 2:/账号id由银行自动提供(
26、从1001递增)scanner = new Scanner(System.in);System.out.print(请输入账户密码:);String passwd1 = scanner.next();scanner = new Scanner(System.in);System.out.print(请再输入账户密码:);String passwd2 = scanner.next();scanner = new Scanner(System.in);System.out.print(请输入户主姓名:);String name = scanner.next();scanner = new Scan
27、ner(System.in);System.out.print(请输入户主身份证号码:);String personId = scanner.next();scanner = new Scanner(System.in);System.out.print(请输入账户类型(0储蓄,1信用):);int type = scanner.nextInt();bank.openAccount(passwd1, passwd2, name, personId, type);break;case 3:bank.saveAccountDate();firstFlag = false;break;default :System.out.println(没有该选项,请重新选择!);break; catch (Exception e) System.out.println(选择输入不正当,请重新选择!);System.out.println(谢谢使用!);