ATM柜员机模拟程序(共32页)

上传人:夏*** 文档编号:46351420 上传时间:2021-12-12 格式:DOC 页数:32 大小:340KB
收藏 版权申诉 举报 下载
ATM柜员机模拟程序(共32页)_第1页
第1页 / 共32页
ATM柜员机模拟程序(共32页)_第2页
第2页 / 共32页
ATM柜员机模拟程序(共32页)_第3页
第3页 / 共32页
资源描述:

《ATM柜员机模拟程序(共32页)》由会员分享,可在线阅读,更多相关《ATM柜员机模拟程序(共32页)(32页珍藏版)》请在装配图网上搜索。

1、精选优质文档-倾情为你奉上阿坝师范高等专科学校电子信息工程系课程设计ATM柜员机模拟系统学生姓名李 其 林专业名称嵌 入 式班 级2011级学 号阿坝师范高等专科学校电子信息工程系2013年6月摘 要通过设计ATM柜员模拟程序,加深自己对Java编程尤其是对Java图形用户界面编程的了解,将自己的学到的编程知识融会贯通,同时培养自身面向对象软件开发的思维,初步了解软件开发的一般流程,提高用Java实际动手能力并增强自己对面向对象的了解。通过这次编程设计,加深了对Java图形界面编程中各个模块和组件的应用了解,以及类和类之间的关系,界面排版的处理等。设计要求是,当输入给定的卡号和密码(初始卡号和

2、密码为)时,系统能登录ATM柜员机系统,用户可以进行以下操作:(1)查询余额:初始余额为10000元。(2)ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。(3)ATM存款:不能出现负存款。(4)修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。该程序设置了7个类,1个主类6个辅助类,6个辅助类都是内部类的形式,辅助类包括五个实现ATM的功能,一个存放客户资料,之所以用内部类来实现是为了在各个界面转换时不至于要创建多个对象,每一个辅助类的对象只要在主类中创建一次就可以在各个内

3、部类中引用。该程序利用的功能是利用Java事件监听技术来实现的,各种功能单独的创建一个类来实现,不会互相混淆,更加容易理清楚思路。设计的程序完美的实现了设计要求,具有查询、取款、存款、修改密码等功能。专心-专注-专业1 前言1.1 设计任务1.1.1 需求说明随着市场经济的繁荣发展,人们的物质生活得到极大的提高,手中的剩余资金也日益增多。受传统观念影响,绝大多数人喜欢把资金投进银行,而在需要使用现金的时候再到银行提取现金。这就导致银行业务的急剧增加。虽然银行网点越来越多,银行的工作效率也随着信息化有较明显的增长,但是依旧不能满足广大用户的需要。而一味的增加营业网点,从理论上虽然能稍微的缓解银行

4、的压力,但是治标不治本,而且每增加一个网点,不仅要付出昂贵的资金成本,还需要长期投入人力资本,成本非常之昂贵。这时候就迫切的需要一种自动的,易于普及的,低成本的设备来解决这一问题。于是ATM机系统应运而生了。本文正是通过设计一个ATM模拟模拟程序来实现ATM机系统的基本功能,充分运用自己所学的Java知识进行设计编程。1.2 设计内容(1)程序要求 (2)算法分析 (3)流程图 (4)源程序 (5)调试及运行结果(6)总结2 程序要求本ATM柜员机的主要功能如下所述:要求使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码为)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:l 查

5、询余额:初始余额为10000元。l ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。l ATM存款:不能出现负存款。l 修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。3 算法分析通过程序要求,我们可以清楚的知道本次设计的ATM柜员模拟程序需要实现四大功能,即查询余额、取款、存款、修改密码。初次之外,作为ATM系统,还需要最基本的两大功能,即登陆和退出。根据上述的功能分析,我们可以吧整个ATM系统分为登陆模块、查询模块、取款模块、存款模块、修改密码模块。除此之外,还有在登陆

6、系统后的功能选择模块,退出功能则镶嵌在各个需要的模块中。由于各个模块的功能实现是通过界面显示出来的,则程序设计又可以理解为几大界面的设计:登陆界面、主界面、查询余额界面、取款界面、存款界面、修改密码界面。除了几大界面之外,还有系统的初始化,主要是初始卡号、密码的设定等。在程序的大体框架确定之后,我们需要了解各个模块所要实现和需要具有的功能。根据现有的银行ATM系统,我们可以很快就可以了解本次设计的ATM系统应该具有的操作。(1)登陆界面用户输入正确的账号和密码就可以登录到该系统的主界面中去,进行相应的操作:取款、存款、查询、修改密码。(2)主界面主界面包括查询、存款、取款、修改密码、退出的功能

7、按钮,按下相应的按钮,可以进行相应的操作。(3)查询界面在主界面中按下查询按钮可以进行查询操作。通过查询功能我们可以查询账户的余额,在查询过程中我们可以选择取款的业务,除此之外,查询界面之中还有返回和退出的操作。返回的操作会使用户回到主界面,退出的操作会使用户直接回到登陆界面。(4)取款界面取款界面既可以通过主界面进入,也可以通过查询、存款等操作过程中的界面进入。取款功能在对话框中输入你想要取出的金额,但是次金额不可以比账户的余额大,且必须是100的整数倍,取款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,则回到主界面。(5)存款界面在主界面按下存款按钮可以进行存

8、款操作,在对话中输入你需要存入的金额,所输入的数字也要是100的整数倍,而且不可以是负数。存款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,则回到主界面。(6)修改密码选择修改密码按钮可以进行修改密码房,但是要先输入就密码正确并且两次输入新密码一致才可以修改密码。修改完成后,会返回主界面。4 流程图图1 程序流程图5 程序源代码及说明5.1 程序源代码import javax.swing.*;import javax.swing.JOptionPane;import java.awt.event.*;class ATMmodel Account myaccount

9、=new Account(); Load load=new Load(); MainFrame Jmain=new MainFrame(); Take take=new Take(); Input input=new Input(); Display dis=new Display(); Setpw setpw=new Setpw(); public ATMmodel() JOptionPane.showMessageDialog(null,欢迎使用ATM柜员模拟系统); public static void main(String args) ATMmodel atm=new ATMmode

10、l(); /*创建账户*/ class Account private int count=10000; /初始账户余额10000 private String account=; /初始账号 private String password=; /初始密码 public Account() public void setpw(String password) this.password=password; public void deccount(int money) count-=money; public void reccount(int money) count+=money; pub

11、lic int get() return count; public String getaccount() /账号 return account; public String getpw() return password; /*主界面*/ class MainFrame extends JFrame public JButton checked; public JButton cunkuan; public JButton quit; public JButton qukuan; public JButton reset; public MainFrame() initComponents

12、(); this.setLocationRelativeTo(null); / this.setVisible(false); /* 控件初始化*/ private void initComponents() cunkuan = new JButton(); qukuan = new JButton(); checked = new JButton(); reset = new JButton(); quit = new JButton();setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle(ATM柜员模拟程序);

13、setName(mianframe); setResizable(false); cunkuan.setText(存款); cunkuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) cunkuanActionPerformed(evt); );qukuan.setText(取款); qukuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) quku

14、anActionPerformed(evt); );checked.setText(查询); checked.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) checkedActionPerformed(evt); );reset.setText(修改密码); reset.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) resetActionPerforme

15、d(evt); );quit.setText(退出); quit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) quitActionPerformed(evt); );GroupLayout layout = new GroupLayout(getContentPane(); /GroupLayout它将组件按层次分组,以决定它们在 Container 中的位置 getContentPane().setLayout(layout); layout.setHorizontal

16、Group( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(cunkuan) .addPreferredGap(javax.swing.La

17、youtStyle.ComponentPlacement.RELATED, 105, Short.MAX_VALUE) .addComponent(reset) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(qukuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE) .addComponent(quit) .

18、addComponent(checked) .addContainerGap() ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cunku

19、an) .addComponent(reset) .addGap(51, 51, 51) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(quit) .addComponent(qukuan) .addGap(57, 57, 57) .addComponent(checked) .addGap(39, 39, 39) ); pack(); private void quitActionPerformed(ActionEvent evt) load.set

20、Visible(true); this.setVisible(false); private void resetActionPerformed(ActionEvent evt) setpw.setVisible(true);this.setVisible(false); private void checkedActionPerformed(ActionEvent evt) dis.setVisible(true); this.setVisible(false); private void qukuanActionPerformed(ActionEvent evt) take.setVisi

21、ble(true); this.setVisible(false); private void cunkuanActionPerformed(ActionEvent evt) input.setVisible(true); this.setVisible(false); /*登录界面*/ class Load extends JFrame public JPasswordField Jpassword; public JTextField accountnum; public JButton commit; private JLabel jL1; private JLabel jL2; pub

22、lic Load() initComponents(); this.setLocationRelativeTo(null); this.setVisible(true); private void initComponents() jL1 = new JLabel(); jL2 = new JLabel(); accountnum = new JTextField(); commit = new JButton(); Jpassword = new JPasswordField(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)

23、; setTitle(ATM柜员模拟程序); setResizable(false); jL1.setText(账号:); jL2.setText(密码:); commit.setText(确定); commit.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) commitActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing

24、.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layou

25、t.createSequentialGroup() .addContainerGap(50, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jL1) .addComponent(jL2) .addGap(31, 31, 31) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addCompon

26、ent(Jpassword) .addComponent(accountnum, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(122, 122, 122) .addComponent(commit) .addContainerGap(72, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLay

27、out.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(85, 85, 85) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(accountnum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERR

28、ED_SIZE) .addComponent(jL1) .addGap(41, 41, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jL2) .addComponent(Jpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPrefe

29、rredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE) .addComponent(commit) .addGap(64, 64, 64) ); pack(); private void commitActionPerformed(ActionEvent evt) if(accountnum.getText().equals(myaccount.getaccount() & Jpassword.getText().equals(myaccount.getpw() Jmain.setVisi

30、ble(true);this.setVisible(false);accountnum.setText();Jpassword.setText();elseJOptionPane.showMessageDialog(null,密码与账户不匹配,请重新输入,出错提示,1);accountnum.setText();Jpassword.setText(); /*取款界面*/class Take extends JFrame public JButton back; public JButton clear; public JButton commit; private JLabel jL1; pu

31、blic JTextField jT1; public JButton quit; String str=; public Take() initComponents(); this.setLocationRelativeTo(null); this.setVisible(false); private void initComponents() jL1 = new JLabel(); jT1 = new JTextField(); commit = new JButton(); back = new JButton(); quit = new JButton(); clear = new J

32、Button(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jL1.setText(取款金额:); commit.setText(确定); commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt); ); back.setText(返回); back.addActionListener(new ActionListener() public vo

33、id actionPerformed(ActionEvent evt) backActionPerformed(evt); ); quit.setText(退出); quit.addActionListener(new ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) quitActionPerformed(evt); ); clear.setText(清除); clear.addActionListener(new ActionListener() public void actionPe

34、rformed(ActionEvent evt) clearActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequential

35、Group() .addGap(41, 41, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jL1) .addGap(33, 33, 33) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) .addGrou

36、p(layout.createSequentialGroup() .addComponent(clear) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE) .addComponent(quit) .addGroup(layout.createSequentialGroup() .addComponent(commit) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147

37、, Short.MAX_VALUE) .addComponent(back) .addContainerGap(69, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(103, 103, 103) .addGroup(layout.createParallelGroup(j

38、avax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jL1) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(61, 61, 61) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

39、.addComponent(commit) .addComponent(back) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clear) .addComponent(quit) .addContainerGap(65, Short.MAX_VALUE) ); pack(); private void clearActionPerformed(ActionEvent evt) str=; jT1.setTex

40、t(str); private void quitActionPerformed(ActionEvent evt) load.setVisible(true);this.setVisible(false); private void backActionPerformed(ActionEvent evt) Jmain.setVisible(true);this.setVisible(false); private void commitActionPerformed(ActionEvent evt) if(Integer.parseInt(jT1.getText()0 & Integer.pa

41、rseInt(jT1.getText()%100=0 & Integer.parseInt(jT1.getText()=5000) myaccount.deccount(Integer.parseInt(jT1.getText(); int result=javax.swing.JOptionPane.showConfirmDialog(null,是否显示余额?,javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE); if(result=javax.swing.JOptionPane.YE

42、S_OPTION) dis.set(String.valueOf(myaccount.get(); str=; jT1.setText(str); dis.setVisible(true); this.setVisible(false); else Jmain.setVisible(true); this.setVisible(false); else JOptionPane.showMessageDialog(null,取款金额不能为负数+n取款金额不能为0+n取款金额必须是100的倍数+n金额一次不能超过5000+n请重新输入你要取的金额数,出错提示,1); str=; jT1.setTe

43、xt(str); /*存款界面*/class Input extends JFrame private JButton clear; private JButton commit; private JLabel jL1; private JTextField jT1; String str=; public Input() initComponents(); this.setLocationRelativeTo(null); this.setResizable(false); this.setVisible(false); private void initComponents() jL1 =

44、 new JLabel(); jT1 = new JTextField(); commit = new JButton(); clear = new JButton(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jL1.setText(存款金额:); commit.setText(确认); commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt)

45、; ); clear.setText(清除); clear.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) clearActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setH

46、orizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(47, 47, 47) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addComponen

47、t(commit) .addGap(111, 111, 111) .addComponent(clear) .addGroup(layout.createSequentialGroup() .addComponent(jL1) .addGap(27, 27, 27) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(50, Short.MAX_VALUE) ); layout.setVerticalGro

48、up( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(88, 88, 88) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jL1) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(87, 87, 87) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A

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