ATM柜员机模拟程序Word文档格式.docx
《ATM柜员机模拟程序Word文档格式.docx》由会员分享,可在线阅读,更多相关《ATM柜员机模拟程序Word文档格式.docx(45页珍藏版)》请在冰点文库上搜索。
设计的程序完美的实现了设计要求,具有查询、取款、存款、修改密码等功能。
1前言
1.1设计任务
1.1.1需求说明
随着市场经济的繁荣发展,人们的物质生活得到极大的提高,手中的剩余资金也日益增多。
受传统观念影响,绝大多数人喜欢把资金投进银行,而在需要使用现金的时候再到银行提取现金。
这就导致银行业务的急剧增加。
虽然银行网点越来越多,银行的工作效率也随着信息化有较明显的增长,但是依旧不能满足广大用户的需要。
而一味的增加营业网点,从理论上虽然能稍微的缓解银行的压力,但是治标不治本,而且每增加一个网点,不仅要付出昂贵的资金成本,还需要长期投入人力资本,成本非常之昂贵。
这时候就迫切的需要一种自动的,易于普及的,低成本的设备来解决这一问题。
于是ATM机系统应运而生了。
本文正是通过设计一个ATM模拟模拟程序来实现ATM机系统的基本功能,充分运用自己所学的Java知识进行设计编程。
1.2设计内容
(1)程序要求
(2)算法分析(3)流程图(4)源程序(5)调试及运行结果(6)总结
2程序要求
本ATM柜员机的主要功能如下所述:
要求使用图形用户界面。
当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
●查询余额:
●ATM取款:
●ATM存款:
●修改密码:
3算法分析
通过程序要求,我们可以清楚的知道本次设计的ATM柜员模拟程序需要实现四大功能,即查询余额、取款、存款、修改密码。
初次之外,作为ATM系统,还需要最基本的两大功能,即登陆和退出。
根据上述的功能分析,我们可以吧整个ATM系统分为登陆模块、查询模块、取款模块、存款模块、修改密码模块。
除此之外,还有在登陆系统后的功能选择模块,退出功能则镶嵌在各个需要的模块中。
由于各个模块的功能实现是通过界面显示出来的,则程序设计又可以理解为几大界面的设计:
登陆界面、主界面、查询余额界面、取款界面、存款界面、修改密码界面。
除了几大界面之外,还有系统的初始化,主要是初始卡号、密码的设定等。
在程序的大体框架确定之后,我们需要了解各个模块所要实现和需要具有的功能。
根据现有的银行ATM系统,我们可以很快就可以了解本次设计的ATM系统应该具有的操作。
(1)登陆界面
用户输入正确的账号和密码就可以登录到该系统的主界面中去,进行相应的操作:
取款、存款、查询、修改密码。
(2)主界面
主界面包括查询、存款、取款、修改密码、退出的功能按钮,按下相应的按钮,可以进行相应的操作。
(3)查询界面
在主界面中按下查询按钮可以进行查询操作。
通过查询功能我们可以查询账户的余额,在查询过程中我们可以选择取款的业务,除此之外,查询界面之中还有返回和退出的操作。
返回的操作会使用户回到主界面,退出的操作会使用户直接回到登陆界面。
(4)取款界面
取款界面既可以通过主界面进入,也可以通过查询、存款等操作过程中的界面进入。
取款功能在对话框中输入你想要取出的金额,但是次金额不可以比账户的余额大,且必须是100的整数倍,取款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,则回到主界面。
(5)存款界面
在主界面按下存款按钮可以进行存款操作,在对话中输入你需要存入的金额,所输入的数字也要是100的整数倍,而且不可以是负数。
存款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,则回到主界面。
(6)修改密码
选择修改密码按钮可以进行修改密码房,但是要先输入就密码正确并且两次输入新密码一致才可以修改密码。
修改完成后,会返回主界面。
4流程图
图1程序流程图
5程序源代码及说明
5.1程序源代码
importjavax.swing.*;
importjavax.swing.JOptionPane;
importjava.awt.event.*;
classATMmodel{
Accountmyaccount=newAccount();
Loadload=newLoad();
MainFrameJmain=newMainFrame();
Taketake=newTake();
Inputinput=newInput();
Displaydis=newDisplay();
Setpwsetpw=newSetpw();
publicATMmodel(){
JOptionPane.showMessageDialog(null,"
欢迎使用ATM柜员模拟系统"
);
}
publicstaticvoidmain(String[]args){
ATMmodelatm=newATMmodel();
/*创建账户*/
classAccount{
privateintcount=10000;
//初始账户余额10000
privateStringaccount="
123456"
;
//初始账号
privateStringpassword="
//初始密码
publicAccount(){
publicvoidsetpw(Stringpassword){
this.password=password;
publicvoiddeccount(intmoney){
count-=money;
publicvoidreccount(intmoney){
count+=money;
publicintget(){
returncount;
publicStringgetaccount(){//账号
returnaccount;
publicStringgetpw(){
returnpassword;
}
}
/*主界面*/
classMainFrameextendsJFrame{
publicJButtonchecked;
publicJButtoncunkuan;
publicJButtonquit;
publicJButtonqukuan;
publicJButtonreset;
publicMainFrame(){
initComponents();
this.setLocationRelativeTo(null);
//this.setVisible(false);
}
/*控件初始化*/
privatevoidinitComponents(){
cunkuan=newJButton();
qukuan=newJButton();
checked=newJButton();
reset=newJButton();
quit=newJButton();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("
ATM柜员模拟程序"
setName("
mianframe"
setResizable(false);
cunkuan.setText("
存款"
cunkuan.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevt){
cunkuanActionPerformed(evt);
});
qukuan.setText("
取款"
qukuan.addActionListener(newActionListener(){
qukuanActionPerformed(evt);
checked.setText("
查询"
checked.addActionListener(newActionListener(){
checkedActionPerformed(evt);
reset.setText("
修改密码"
reset.addActionListener(newActionListener(){
resetActionPerformed(evt);
quit.setText("
退出"
quit.addActionListener(newActionListener(){
quitActionPerformed(evt);
GroupLayoutlayout=newGroupLayout(getContentPane());
//GroupLayout它将组件按层次分组,以决定它们在Container中的位置
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cunkuan)
.addPreferredGap(javax.swing.LayoutStyle.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))
.addComponent(checked))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(46,46,46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addGap(51,51,51)
.addComponent(quit)
.addComponent(qukuan))
.addGap(57,57,57)
.addComponent(checked)
.addGap(39,39,39))
pack();
privatevoidquitActionPerformed(ActionEventevt){
load.setVisible(true);
this.setVisible(false);
privatevoidresetActionPerformed(ActionEventevt){
setpw.setVisible(true);
this.setVisible(false);
privatevoidcheckedActionPerformed(ActionEventevt){
dis.setVisible(true);
privatevoidqukuanActionPerformed(ActionEventevt){
take.setVisible(true);
privatevoidcunkuanActionPerformed(ActionEventevt){
input.setVisible(true);
}
/*登录界面*/
classLoadextendsJFrame{
publicJPasswordFieldJpassword;
publicJTextFieldaccountnum;
publicJButtoncommit;
privateJLabeljL1;
privateJLabeljL2;
publicLoad(){
this.setVisible(true);
privatevoidinitComponents(){
jL1=newJLabel();
jL2=newJLabel();
accountnum=newJTextField();
commit=newJButton();
Jpassword=newJPasswordField();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jL1.setText("
账号:
"
jL2.setText("
密码:
commit.setText("
确定"
commit.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
commitActionPerformed(evt);
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(getContentPane());
layout.setHorizontalGroup(
.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)
.addComponent(Jpassword)
.addComponent(accountnum,javax.swing.GroupLayout.DEFAULT_SIZE,143,Short.MAX_VALUE)))
.addGap(122,122,122)
.addComponent(commit)))
.addContainerGap(72,Short.MAX_VALUE))
.addGap(85,85,85)
.addComponent(accountnum,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jL1))
.addGap(41,41,41)
.addComponent(jL2)
.addComponent(Jpassword,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,72,Short.MAX_VALUE)
.addComponent(commit)
.addGap(64,64,64))
privatevoidcommitActionPerformed(ActionEventevt){
if(accountnum.getText().equals(myaccount.getaccount())&
&
Jpassword.getText().equals(myaccount.getpw()))
{
Jmain.setVisible(true);
this.setVisible(false);
accountnum.setText("
Jpassword.setText("
else{
JOptionPane.showMessageDialog(null,"
密码与账户不匹配,请重新输入"
"
出错提示"
1);
}
/*取款界面*/
classTakeextendsJFrame{
publicJButtonback;
publicJButtonclear;
publicJTextFieldjT1;
Stringstr="
public