BAM银行账户管理系统java类.doc

上传人:夺命阿水 文档编号:21140 上传时间:2022-07-11 格式:DOC 页数:17 大小:174.50KB
返回 下载 相关 举报
BAM银行账户管理系统java类.doc_第1页
第1页 / 共17页
BAM银行账户管理系统java类.doc_第2页
第2页 / 共17页
BAM银行账户管理系统java类.doc_第3页
第3页 / 共17页
BAM银行账户管理系统java类.doc_第4页
第4页 / 共17页
BAM银行账户管理系统java类.doc_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《BAM银行账户管理系统java类.doc》由会员分享,可在线阅读,更多相关《BAM银行账户管理系统java类.doc(17页珍藏版)》请在课桌文档上搜索。

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

2、、封装、多态、抽象,在多态中又涉与重载和重 写,请读者注意相关联系关注注释 4、可以实现数据保存功能,数据将保存在文件中即当你注册了一个账户,下次再登 陆系统时,可以实现与上次最后的操作相衔接 5、账户号自动生成,比拟符合现实 5.转账一个账户到另一个账户等 7、运行时界面简示1.初始界面账户登录须知事项:1、本系统采用的编程环境是JDK1.7,jer7。所以,运行代码需要保持电脑上所装的JDK为1.7以上版本,如有报错,只需换个高一点的版本即可。注意:第一次装JDK,要配置环境变量请查阅相关资料,比拟简单2、本系统代码涉与到包,所以如果报名不一致就会报错,解决方法:修改一下包名即可3、建议把

3、各个类写在同一个包下面,且每一个类单独写一个java文件,如如下图:4、在运行程序前,需要在项目下面新建一个account.txt用来保存数据文件如上图,并在其中写入至少一个账户信息,如如下图,其中每项代表的意思,请读者参照代码内的注释,否如此在初始化的时候会因为找不到账户信息,从而产生异常。系统源码:Account类package .qx;/包名/* */publicabstractclass Account /属性protectedlong id;protected String password;protected String name;protected String personI

4、d;protectedint accountType;protecteddouble balance;/构造方法public Account()super();public Account(long id, String password, String name, String personId,int accoutType,double balance) super();this.id = id;this.password = password;this.name = name;this.personId = personId;this.accountType = accountType;

5、this.balance = balance;/getXxx,setXxx方法publiclong getId() return id;publicvoid setId(long id) this.id = id;public String getPassword() return password;publicvoid setPassword(String password) this.password = password;public String getName() return name;publicvoid setName(String name) this.name = name

6、;public String getPersonId() return personId;publicvoid setPersonId(String personId) this.personId = personId;publicint getAccountType() return accountType;publicvoid setAccountType(int accountType) this.accountType = accountType;publicdouble getBalance() return balance;publicvoid setBalance(double

7、balance) this.balance = balance;/* * 存款 */publicvoid deposit(double money)balance += money;/* * 取款取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类 */publicabstractvoid withdraw(double money);SavingAccount类package .qx;/* * 储蓄账户类 */publicclass SavingAccount extends Account /构造函数public SavingAccount() super();pu

8、blic SavingAccount(long id, String password, String name, String personId,int accountType, double balance) super(id, password, name, personId, accountType, balance);/对父类的withdraw()实现publicvoid withdraw(double money)if(balance money)System.out.println(对不起,账户余额不足!);elsebalance -= money;CresitAccount类p

9、ackage .qx;/* * 信用账户类,增加一个信用额度ceiling属性 */publicclass CreditAccount extends Accountprivateint ceiling;/构造函数public CreditAccount()super();public CreditAccount(long id, String password, String name,String personId,int accountType, double balance, int ceiling)super(id, password, name, personId, account

10、Type, balance);this.ceiling = ceiling;/getXxx,setXxx方法publicint getCeiling() return ceiling;publicvoid setCeiling(int ceiling) this.ceiling = ceiling;/实现父类的withdraw()publicvoid withdraw(double money)if(balance + ceiling) = accounts.length)/扩容Account newAccounts = new Accountaccounts.length*2;/copy原来

11、的相关数据System.arraycopy(accounts, 0, newAccounts, 0, accounts.length);/将newAccounts赋给accountsaccounts = newAccounts;accountsnumber = account;elseaccountsnumber = account;System.out.println(开户成功!账户信息见下);System.out.println(您的卡号为:+id+n+您的密码为:+passwd1+n+您的户名为:+name+n+您的某某号为:+personId+n+您的账户类型为:+type+n);ac

12、count.accountType = type;number+;id+;return account;/此时开户成功elseSystem.out.println(对不起!您两次密码输入不匹配,开户失败!);return null;/此时开户失败/* * 保存数据 */public void saveAccountDate()BufferedWriter bufWriter=null;try Properties props=System.getProperties();String path=props.getProperty(user.dir);bufWriter=new Buffered

13、Writer(new FileWriter(new File(path,account.txt);for(int i = 0;i accounts.length;i+)/假如存在账户if(accountsi != null)bufWriter.write(accountsi.id+,);bufWriter.write(accountsi.getPassword()+,);bufWriter.write(accountsi.getName()+,);bufWriter.write(accountsi.getPersonId()+,);bufWriter.write(accountsi.getAc

14、countType()+,);bufWriter.write(Double.toString(accountsi.getBalance();bufWriter.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 catc

15、h blocke.printStackTrace();/* * 登录验证 */public Account verifyAccount(long id, String 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;ret

16、urn account;/* * 转账验证方法的重载 */public Account verifyAccount(long id)Account account = null;for(int i = 0;i accounts.length;i+)/假如存在账户if(accountsi != null)/验证id号和passwordif(id = accountsi.getId()account = accountsi;break;elsebreak;return account;/* * 转账 */public void transferAccount(Account account1, A

17、ccount 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 .qx;import java.io.BufferedReader;import

18、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 class ATM /属性private Bank bank;/构造函数public ATM() bank = new Bank();/main方法public static void main(String args)ATM atm = new

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

20、 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);System.out.print(请输入银行密码:);String password = scanner.next();Account account = bank.verifyAccount(id, password);if(account !=

21、 null)/标号,判断是否退出二级菜单boolean secondFlag = true;while(secondFlag)/二级菜单System.out.println(*欢迎使用XXX银行模拟ATM系统,请按如下步骤操作*);System.out.println( *1.查询账户余额);System.out.println( *2.存款);System.out.println( *3.取款);System.out.println( *4.转账);System.out.println( *5.退卡);scanner = new Scanner(System.in);System.out.p

22、rint(请选择:);try int choice2 = scanner.nextInt();switch(choice2)case 1:System.out.println(您账户的当前余额为:+account.getBalance();break;case 2:scanner = new Scanner(System.in);System.out.print(请输入您的存款金额:);double money1 = scanner.nextDouble();bank.deposit(account, money1);break;case 3:scanner = new Scanner(Sys

23、tem.in);System.out.print(请输入您的取款金额:);double money2 = scanner.nextDouble();bank.withdraw(account, money2);break;case 4:scanner = new Scanner(System.in);System.out.print(请输入您要转入账户的卡号:);long id2 = scanner.nextLong();Account account2 = bank.verifyAccount(id2);if(account2 != null)scanner = new Scanner(Sy

24、stem.in);System.out.print(请输入您要转入账户的金额:);double money = scanner.nextLong();if(money = account.balance)bank.transferAccount(account, account2, money);System.out.println(转账成功!);elseSystem.out.println(抱歉,您账户没有足够的金额!请查看后重新选择输入!);elseSystem.out.println(抱歉,没有找到您要转入的账户信息!请核对后重新选择输入!);break;case 5:secondFla

25、g = false;break;default:System.out.println(没有该选项,请重新选择!);break; catch (Exception e) System.out.println(选择输入不合法,请重新选择!);elseSystem.out.println(没有此账户,请先开户!);break;case 2:/账号id由银行自动提供从1001递增scanner = new Scanner(System.in);System.out.print(请输入账户密码:);String passwd1 = scanner.next();scanner = new Scanner

26、(System.in);System.out.print(请再输入账户密码:);String passwd2 = scanner.next();scanner = new Scanner(System.in);System.out.print(请输入户主某某:);String name = scanner.next();scanner = new Scanner(System.in);System.out.print(请输入户主某某:);String personId = scanner.next();scanner = new Scanner(System.in);System.out.pr

27、int(请输入账户类型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(谢谢使用!);- 17 - / 17

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号