1、ATM管理系统java窗口界面完整版ATM管理系统引言:本系统采用JAVA语言并在eclipse环境下编写测试完成,涉及类的概念,以及面向对象的几大特性(继承,封装,多态,抽象),也有异常处理机制,采用集合(更好)存储账户数据,基本可以满足大多数BAM系统的相关实现。JAVA类的面相对象的应用,拥有异常处理机制,不会因为输入错误而导致程序崩溃。本系统各个类之间的相互关系,涉及继承、封装、多态、抽象,在多态中又涉及重载和重写,相关联系请关注代码注释。可以实现数据保存功能,数据将保存在文件中(即当你注册了一个账户,下次再登录系统时,可以实现与上次最后的操作相衔接)。最后账户号自动生成,比较符合现实
2、。1、软件需求分析 1.1 市场需求 由于的各方面发展速度的大幅提高,几乎所有的银行都配备了不用繁琐的人工操作的ATM自动取款机。人们可以随时随地进行交易,不再受银行的服务时间的约束,取款时也为人们节省了很多时间,方便快捷。对于配有ATM自动取款机的银行,客户较多,系统需操作方便,信息读取与存储及时快速,方便客户进行自由交易和系统管理员对信息的管理。1.2 功能需求软件应包含取款、存款、转账、查询、修改密码等ATM机的主要功能。2、程序结构本系统主要有7个类,即Account(账户类)SaveAccount(储蓄账户类):不能透支CreditAccount(信用账户类):可以透支Bank(银行
3、类)ATMOpenAccountFrame(开户窗口页面)ATMLoginFrame(登录窗口页面)ATMMainFrame(操作窗口页面) 注:带有完善的相关信息提示弹出窗口 (见下面截图)类的具体属性级行为见代码3、功能介绍主要功能有:1.开户(储蓄账户信用账户) 2.查询账户余额 3.存款 4.取款 5.转账(一个账户到另一个账户)4、软件设计 7、运行时界面简示 1.初始界面(账户登录) 2.账户登录后界面 3.相关信息提示一览(只列举一部分)1、查询: 2、存款: 3、取款: 4、转账: 4、用户开户界面:注意事项:1、本系统采用的编程环境是JDK1.7,jer7。所以,运行代码需要
4、保持电脑上所装的JDK为1.7以上版本,如有报错,只需换个高一点的版本即可。注意:第一次装JDK,要配置环境变量(请查阅相关资料,比较简单)2、本系统代码涉及到包,所以如果报名不一致就会报错,解决方法:修改一下包名即可3、建议把各个类写在同一个包下面,且每一个类单独写一个java文件,如下图: 4、在运行程序前,需要在项目下面新建一个account.txt(用来保存数据)文件(如上图),并在其中写入至少一个账户信息,(如下图,其中每项代表的意思,请读者参照代码内的注释),否则在初始化的时候会因为找不到账户信息,从而产生异常。 系统源码:Account类package com.qx;import
5、 javax.swing.JOptionPane;/* * 账户类:包含两种账户类型-1.储蓄账户 2.信用账户 */public abstract class Account /属性 protected long id; protected String password; protected String name; protected String personId; protected String accountType; protected double balance; /构造方法 public Account() super(); public Account(long id,
6、 String password, String name, String personId, String type,double balance) super(); this.id = id; this.password = password; this.name = name; this.personId = personId; this.accountType = type; this.balance = balance; /getXxx,setXxx方法 public long getId() return id; public void setId(long id) this.id
7、 = id; public String getPassword() return password; 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.pe
8、rsonId = personId; public String getAccountType() return accountType; public void setAccountType(String accountType) this.accountType = accountType; public double getBalance() return balance; public void setBalance(double balance) this.balance = balance; /* * 存款 */ public void deposit(double money)
9、balance += money; /* * 取款(取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类) */ public abstract void withdraw(double money); SavingAccount类package com.qx;import javax.swing.JOptionPane;/* * 储蓄账户类 */public class SavingAccount extends Account /构造函数 public SavingAccount() super(); public SavingAccount(long id, St
10、ring password, String name, String personId,String accountType, double balance) super(id, password, name, personId, accountType, balance); /对父类的withdraw()实现 public void withdraw(double money) if(balance money) /*System.out.println(对不起,账户余额不足!);*/ JOptionPane.showMessageDialog(null, 对不起,账户余额不足!, 信息提示
11、,JOptionPane.ERROR_MESSAGE); else balance -= money; CreditAccount类package com.qx;import javax.swing.JOptionPane;/* * 信用账户类,增加一个信用额度ceiling属性 */public class CreditAccount extends Account private int ceiling; /构造函数 public CreditAccount() super(); public CreditAccount(long id, String password, String n
12、ame, String personId,String 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 w
13、ithdraw(double money) if(balance + ceiling) money) /*System.out.println(对不起,已超出您的信用额度!);*/ JOptionPane.showMessageDialog(null, 对不起,已超出您的信用额度!, 信息提示,JOptionPane.ERROR_MESSAGE); else balance -= money; Bank类package com.qx;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;i
14、mport java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Properties;import javax.swing.JOptionPane;/* * Bank类 * 编写Bank类,属性:1.当前所有的账户对象的集合,存放在数组中2.当前账户
15、数量方法:1.用户开户,需要的参数:id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Account对象的账号, 提示:用s1.equals(s2) 可以比较s1,s2两个字符串的值是否相等.账户类型是一个整数,为0的时候表示储蓄账户,为1的时候表示信用账户2.用户登录,参数:id,密码 返回登录账户的账号3.用户存款,参数:id,存款数额,返回void4.用户取款,参数:id,取款数额,返回void5.查询余额,参数:id,返回该账户的余额 double用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数 */public class Bank /*pr
16、ivate Account accounts = new Account20;*/ private List accountsList; private int number;/账户数目 private int id = 1001;/确定银行账号从1001开始生成,即第一个账户的账号是1001 /构造函数 public Bank() accountsList=new ArrayList(); number = 0; BufferedReader bufReader = null; Properties props=System.getProperties(); String path=prop
17、s.getProperty(user.dir); try bufReader=new BufferedReader(new FileReader(new File(path,account.txt); String s = bufReader.readLine(); while(s != null) String str = s.split(,); if(str4.equals(0) Account savingAcc = new SavingAccount(Long.parseLong(str0), str1.toString(), str2.toString(), str3.toStrin
18、g(),str4.toString(), Double.parseDouble(str5); accountsList.add(savingAcc); else Account creditAcc = new CreditAccount(Long.parseLong(str0), str1.toString(), str2.toString(), str3.toString(),str4.toString(), Double.parseDouble(str5),5000); accountsList.add(creditAcc); number +; id+; s = bufReader.re
19、adLine(); catch (NumberFormatException e) / TODO Auto-generated catch block e.printStackTrace(); catch (FileNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); finally try if(bufReader != null) bufRe
20、ader.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); /getXxx,setXxx public List getAccounts() return accountsList; public void setAccounts(List accounts) this.accountsList = accounts; public int getNumber() return number; public void setNumber(int number) this.n
21、umber = number; public int getId() return id; public void setId(int id) this.id = id; /* * 开户 */ public Account openAccount(String passwd1, String passwd2, String name, String personId, String type) /创建一个新账户 Account account = null; /判断两次密码是否一致 if(passwd1.equals(passwd2) /若一致,再判断账户类型(根据type的值) if(typ
22、e.equals(1) /可令开始余额为10,信用额度为5000 account = new CreditAccount(id, passwd1, name, personId, type, 10, 5000); else account = new SavingAccount(id, passwd1, name, personId, type, 10); /将账户存入账户集合accountsList中 accountsList.add(account); JOptionPane.showMessageDialog(null, 开户成功!,信息提示, JOptionPane.INFORMATI
23、ON_MESSAGE); JOptionPane.showMessageDialog(null, 您的卡号为:+id+n+ 您的密码为:+passwd1+n+您的户名为:+name+n+ 您的身份证号为:+personId+n+您的账户类型为:+type+n,信息提示, JOptionPane.INFORMATION_MESSAGE); account.accountType = type; number+; id+; return account;/此时开户成功 else JOptionPane.showMessageDialog(null, 对不起!您两次密码输入不匹配,开户失败!, 信息
24、提示,JOptionPane.ERROR_MESSAGE); return null;/此时开户失败 /* * 保存数据 */ public void saveAccountDate() BufferedWriter bufWriter=null; try Properties props=System.getProperties(); String path=props.getProperty(user.dir); String s = null; bufWriter=new BufferedWriter(new FileWriter(new File(path,account.txt);
25、for(Iterator iterator = accountsList.iterator();iterator.hasNext();) /若存在账户 Account acc = (Account) iterator.next(); /写入账户信息到account.txt bufWriter.write(acc.id+,); bufWriter.write(acc.getPassword()+,); bufWriter.write(acc.getName()+,); bufWriter.write(acc.getPersonId()+,); bufWriter.write(acc.getAcc
26、ountType()+,); bufWriter.write(Double.toString(acc.getBalance(); bufWriter.newLine(); bufWriter.flush();/清空缓存中的内容 catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); finally try if(bufWriter!=null) bufWriter.close(); catch (IOException e) / TODO Auto-generated catch block e.
27、printStackTrace(); /* * 登录验证 */ public Account verifyAccount(long id, String password) Account account = null; Account acc = null; for(Iterator iterator = accountsList.iterator(); iterator.hasNext();) /若存在账户 acc = (Account) iterator.next(); if (acc != null) if (id = acc.getId() & password.equals(acc.getPassword() account = acc; break; else break; return account; /* * 转账验证(方法的重载) */ public Account verifyAccount(long id) Account account = null; Account acc = null; for(Iterator iterator = accountsList.iterator();
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2