bam银行账户管理系统(java类)

上传人:栀**** 文档编号:60217312 上传时间:2022-03-07 格式:DOC 页数:17 大小:291.50KB
收藏 版权申诉 举报 下载
bam银行账户管理系统(java类)_第1页
第1页 / 共17页
bam银行账户管理系统(java类)_第2页
第2页 / 共17页
bam银行账户管理系统(java类)_第3页
第3页 / 共17页
资源描述:

《bam银行账户管理系统(java类)》由会员分享,可在线阅读,更多相关《bam银行账户管理系统(java类)(17页珍藏版)》请在装配图网上搜索。

1、.BAM 银行账户管理系统( ATM 管理系统)本系统采用JAVA 语言并在eclipse 环境下编写测试完成,涉及类的概念,以及面向对象的几大特性(继承,封装,多态,抽象),也有异常处理机制,基本可以满足大多数BAM系统的相关实现,且代码标注大量注释,读者可以很轻松地理解相关逻辑,大家可以开心参考。系统简介:1、JAVA 类的面相对象的应用,拥有异常处理机制,不会因为输入错误而导致程序崩溃2、主要有5 个类,即 Account (账户类) SaveAccount (储蓄账户类) :不能透支CreditAccount (信用账户类) :可以透支Bank (银行类)ATM ( ATM 类)类的具

2、体属性级行为见代码3、各个类之间的相互关系,涉及继承、封装、多态、抽象,在多态中又涉及重载和重写,请读者注意相关联系(关注注释)4、可以实现数据保存功能,数据将保存在文件中(即当你注册了一个账户,下次再登陆系统时,可以实现与上次最后的操作相衔接)5、账户号自动生成,比较符合现实6、主要功能有:1.开户2.查询账户余额3.存款4.取款5.转账(一个账户到另一个账户)等 7、运行时界面简示1.初始界面(账户登录)Word 专业资料.2.账户登录后界面注意事项:1、本系统采用的编程环境是JDK1.7,jer7 。所以, 运行代码需要保持电脑上所装的JDK为 1.7 以上版本,如有报错,只需换个高一点

3、的版本即可。注意:第一次装JDK,要配置环境变量(请查阅相关资料,比较简单)2、本系统代码涉及到包,所以如果报名不一致就会报错,解决方法:修改一下包名即可3、建议把各个类写在同一个包下面,且每一个类单独写一个java 文件,如下图:4、在运行程序前,需要在项目下面新建一个account.txt (用来保存数据)文件(如上图),并在其中写入至少一个账户信息,(如下图,其中每项代表的意思,请读者参照代码的注释),否则在初始化的时候会因为找不到账户信息,从而产生异常。Word 专业资料.系统源码:Account 类package .qx;/ 包名/* 账户类 : 包含两种账户类型-1. 储蓄账户2.

4、信用账户*/public abstract class Account / 属性protectedlong id;protectedString password;protectedString name;protectedString personId;protectedint accountType;protecteddouble balance;/ 构造方法public Account()super();public Account( long id, String password, String name, String personId, int accoutType, doubl

5、e balance) super();this .id = id;this .password = password;this .name = name;this .personId = personId;this .accountType = accountType;Word 专业资料.this .balance = balance;/getXxx,setXxx方法public long getId() return id;public void setId( long id) this .id = id;public String getPassword() return password

6、;public void setPassword(String password) this .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

7、 accountType;public void setAccountType( int accountType) this .accountType = accountType;public double getBalance() return balance;public void setBalance(doublebalance) this .balance = balance;/* 存款*/public void deposit( double money)balance += money;Word 专业资料./* 取款(取款方式由账户类型决定,所以设为抽象方法,相应的Account

8、类应设为抽象类)*/public abstract void withdraw(double money);SavingAccount 类package .qx;/* 储蓄账户类*/public class SavingAccountextends Account / 构造函数public SavingAccount() super();public SavingAccount( long id, String password, String name, String personId, int accountType, double balance) super(id, password,

9、 name, personId, accountType, balance);/ 对父类的 withdraw()实现public void withdraw(double money)if (balance money)System.out .println( 对不起,账户余额不足!);elsebalance -= money;CresitAccount 类Word 专业资料.package .qx;/* 信用账户类,增加一个信用额度ceiling 属性*/public class CreditAccountextends Accountprivate int ceiling;/ 构造函数pu

10、blic CreditAccount()super();public CreditAccount( long id, String 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

11、 setCeiling( int ceiling) this .ceiling = ceiling;/ 实现父类的 withdraw()public 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 赋给 accoun

12、tsWord 专业资料.accounts = newAccounts;accountsnumber = account;elseaccountsnumber = account;开户成功!账户信息见下);您的卡号为: +id+n+您的密码为: +passwd1+n+您的户名为: +name+n+ 您 的 身 份 证 号 为 : +personId+n+您 的 账 户 类 型 为 :+type+n);account.accountType = type;number+;id+;return account;/此时开户成功else对不起!您两次密码输入不匹配,开户失败! ! ); return n

13、ull;/ 此时开户失败/* 保存数据*/public void saveAccountDate()BufferedWriter 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)/

14、 写入账户信息到 account.txt bufWriter.write(accountsi.id+,); bufWriter.write(accountsi.getPassword()+,); bufWriter.write(accountsi.getName()+,); bufWriter.write(accountsi.getPersonId()+,); bufWriter.write(accountsi.getAccountType()+,); bufWriter.write(Double.toString(accountsi.getBalance();Word 专业资料.bufWri

15、ter.newLine();elsebreak;bufWriter.flush();/清空缓存中的容 catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry if(bufWriter!=null)bufWriter.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace();/* 登录验证*/public Account verifyAccount(long id, St

16、ring password)Account account = null;for(int i = 0;i accounts.length;i+)/ 若存在账户 if(accountsi != null)/ 验证 id 号和 passwordif(id = accountsi.getId() & password.equals(accountsi.getPassword()account = accountsi;break;elsebreak;Word 专业资料.return account;/* 转账验证(方法的重载)*/public Account verifyAccount(long id

17、)Account account = null;for(int i = 0;i accounts.length;i+)/ 若存在账户 if(accountsi != null)/ 验证 id 号和 password if(id = accountsi.getId()account = accountsi;break;elsebreak;return account;/* 转账*/public void transferAccount(Account account1, Account account2, double money) account1.withdraw(money);accoun

18、t2.deposit(money);/* 存款*/public void deposit(Account account, double money)account.deposit(money);/* 取款*/public void withdraw(Account account, double money)account.withdraw(money);Word 专业资料.ATM 类package .qx;/* ATM 类,提供用户界面操作*/public class ATM / 属性private Bank bank;/ 构造函数public ATM() bank = new Bank(

19、);/main方法public static void main(String args)ATM atm = new ATM();/实例化 ATMBank bank = atm.bank;/ 标号,判断是否退出一级菜单boolean firstFlag = true;while(firstFlag)/ 一级菜单欢迎使用 XXX 银行模拟 ATM 系统,请按如下步骤操作 *);System.out.println(*1.用已有账户登录 );System.out.println(*2.没有账户,开户 );System.out.println(*3.退出 );Scanner scanner = ne

20、w Scanner(System.in);System.out.print(请选择: );try int choice1 = scanner.nextInt();switch(choice1)case 1:scanner = new Scanner(System.in);Word 专业资料.请输入银行卡号:);long id = scanner.nextInt();scanner = new Scanner(System.in);请输入银行密码:);String password = scanner.next();Account account = bank.verifyAccount(id,

21、 password);if(account != null)/ 标号,判断是否退出二级菜单 boolean secondFlag = true; while(secondFlag)/ 二级菜单欢迎使用 XXX 银行模拟 ATM 系统,请按如下步骤操作*);*1. 查询账户余额);*2. 存款 );*3. 取款 );*4. 转账 );*5. 退卡 );scanner = new Scanner(System.in);请选择: );try int choice2 = scanner.nextInt();switch(choice2)case 1:您账户的当前余额为:+account.getBala

22、nce();break;case 2:scanner = new Scanner(System.in);请输入您的存款金额:);double money1 = scanner.nextDouble();bank.deposit(account, money1);break;case 3:scanner = new Scanner(System.in);请输入您的取款金额:);double money2 = scanner.nextDouble();bank.withdraw(account, money2);break;case 4:scanner = new Scanner(System.i

23、n);请输入您要转入账户的卡号:);long id2 = scanner.nextLong();Word 专业资料.Account account2 = bank.verifyAccount(id2);if(account2 != null)scanner = new Scanner(System.in);请输入您要转入账户的金额: );double money = scanner.nextLong();if(money = account.balance)bank.transferAccount(account, account2,money);转账成功!);else抱歉,您账户没有足够的金

24、额!请查看后重新选择输入!);else抱歉,没有找到您要转入的账户信息!请核对后重新选择输入!);break;case 5:secondFlag = false;break;default:没有该选项,请重新选择!);break; catch (Exception e) 选择输入不合法,请重新选择!);else没有此账户,请先开户!);break;case 2:/ 账号 id 由银行自动提供(从1001 递增)scanner = new Scanner(System.in);Word 专业资料.请输入账户密码:);String passwd1 = scanner.next();scanner

25、= new Scanner(System.in);请再输入账户密码:);String passwd2 = scanner.next();scanner = new Scanner(System.in);请输入户主姓名:);String name = scanner.next();scanner = new Scanner(System.in);请输入户主身份证:);String personId = scanner.next();scanner = new Scanner(System.in);请输入账户类型(0 储蓄, 1 信用): );int type = scanner.nextInt();bank.openAccount(passwd1, passwd2, name, personId, type);break;case 3:bank.saveAccountDate();firstFlag = false;break;default :没有该选项,请重新选择!);break; catch (Exception e) 选择输入不合法,请重新选择!);谢谢使用! );Word 专业资料

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!