java程序设计ATM柜员机模拟程序.docx

上传人:b****9 文档编号:25168963 上传时间:2023-06-05 格式:DOCX 页数:47 大小:226.98KB
下载 相关 举报
java程序设计ATM柜员机模拟程序.docx_第1页
第1页 / 共47页
java程序设计ATM柜员机模拟程序.docx_第2页
第2页 / 共47页
java程序设计ATM柜员机模拟程序.docx_第3页
第3页 / 共47页
java程序设计ATM柜员机模拟程序.docx_第4页
第4页 / 共47页
java程序设计ATM柜员机模拟程序.docx_第5页
第5页 / 共47页
点击查看更多>>
下载资源
资源描述

java程序设计ATM柜员机模拟程序.docx

《java程序设计ATM柜员机模拟程序.docx》由会员分享,可在线阅读,更多相关《java程序设计ATM柜员机模拟程序.docx(47页珍藏版)》请在冰豆网上搜索。

java程序设计ATM柜员机模拟程序.docx

java程序设计ATM柜员机模拟程序

 

 

面向对象课程设计(Java)

题目:

ATM柜员机模拟程序

专业:

电子商务

班级:

学生姓名:

指导教师:

2013年1月5日

目录1

1设计内容1

2程序要求1

3算法分析1

4流程图3

5程序源代码及说明4

5.1程序源代码4

5.2源代码说明22

521源代码中自定义类的说明:

22

5.2.2源代码中的事件监听器23

6调试及运行结果24

7心得体会30

错误!

未定义书签

1设计内容

(1)程序要求

(2)算法分析(3)流程图(4)源程序(5)调试及运行结果

(6)体会

2程序要求

本ATM巨员机的主要功能如下所述:

要求使用图形用户界面。

当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM巨员机系统,用户可以按照以下规则进行:

查询余额:

初始余额为10000元。

ATM取款:

每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。

ATM存款:

不能出现负存款。

修改密码:

新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。

3算法分析

通过程序要求,我们可以清楚的知道本次设计的ATM巨员模拟程序需要实现四大功能,即查询余额、取款、存款、修改密码。

初次之外,作为ATM系统,还需要最基本的两大功能,即登陆和退出。

根据上述的功能分析,我们可以吧整个ATM系统分为登陆模块、查询模块、取款模块、存款模块、修改密码模块。

除此之外,还有在登陆系统后的功能选择模块,退出功能则镶嵌在各个需要的模块中。

由于各个模块的功能实现是通过界面显示出来的,则程序设计又可以理解为几大界面的设计:

登陆界面、主界面、查询余额界面、取款界面、存款界面、修改密码界面。

除了几大界面之外,还有系统的初始化,主要是初始卡号、密码的设定等。

在程序的大体框架确定之后,我们需要了解各个模块所要实现和需要具有的功能。

根据现有的银行ATM系统,我们可以很快就可以了解本次设计的ATM系统应该具有的操作。

(1)登陆界面

用户输入正确的账号和密码就可以登录到该系统的主界面中去,进行相应的操作:

取款、存款、查询、修改密码。

(2)主界面

主界面包括查询、存款、取款、修改密码、退出的功能按钮,按下相应的按钮,可以进行相应的操作。

(3)查询界面

在主界面中按下查询按钮可以进行查询操作。

通过查询功能我们可以查询账户的余

额,在查询过程中我们可以选择取款的业务,除此之外,查询界面之中还有返回和退出的操作。

返回的操作会使用户回到主界面,退出的操作会使用户直接回到登陆界面。

(4)取款界面

取款界面既可以通过主界面进入,也可以通过查询、存款等操作过程中的界面进入。

取款功能在对话框中输入你想要取出的金额,但是次金额不可以比账户的余额大,且必须是100的整数倍,取款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,贝U回到主界面。

(5)存款界面

在主界面按下存款按钮可以进行存款操作,在对话中输入你需要存入的金额,所输入的数字也要是100的整数倍,而且不可以是负数。

存款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面,选“否”的话,则回到主界面。

(6)修改密码

选择修改密码按钮可以进行修改密码房,但是要先输入就密码正确并且两次输入新密码一致才可以修改密码。

修改完成后,会返回主界面。

 

4流程图

图1程序流程图

 

 

5程序源代码及说明

5.1程序源代码

importjavax.swing.*;

importjavax.swing.JOptionPane;importjava.awt.event.*;

publicclassATMmodel{

Accountmyaccount=newAccount();

Loadload=newLoad();

MainFrameJmain=newMainFrame();

Taketake=newTake();

Inputinput=newlnput();

Displaydis=newDisplay();

Setpwsetpw=newSetpw();

publicATMmodel(){

JOptionPane.showMessageDialog(null,"欢迎使用ATMf!

员模拟系统");

}

publicstaticvoidmain(String[]args){

ATMmodelatm=_newATMmodel();

}—

/*创建账户*/

classAccount{

初始账户余额10000

初始账号

初始密码

privateintcount=1OOOO;//privateStringaccount="123456";//

privateStringpassword="123456";//

publicAccount(){

}

publicvoidsetpw(Stringpassword){this.password=password;

}

publicvoiddeccount(intmoney){count-=money;

}

publicvoidreccount(intmoney){count+=money;

publicreturn

Stringgetpw(){password;

}

/*主界面*/

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(){

publicvoidactionPerformed(ActionEventevt){qukuanActionPerformed(evt);

}

});

checked.setText(”查询");

checked.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventevt){checkedActionPerformed(evt);

}

});

reset.setText("修改密码");

reset.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventevt){resetActionPerformed(evt);

}

});

quit.setText("退出");

quit.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventevt){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.GroupLayou

t.Alignment.LEADING

.addGroup(layout.createSequentialGroup().addComponent(cunkuan)

.addPreferredGap(javax.swing^LayoutStyle.ComponentP

lacement.RELATED105,Short.MAX_VAL(UE

.addComponent(reset))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

.addComponent(qukuan)

.addPreferredGap(javax.swing^LayoutStyle.ComponentP

lacement.RELATED143,Short.MAX_VAL(UE

.addComponent(quit))

.addComponent(checked))

.addContainerGap())

);

layout.setVerticalGroup(

LEADING

layout.createParallelGroup(javax.swing.GroupLayout.Alignment..addGroup(layout.createSequentialGroup()

.addGap(46,46,46).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE

.addComponent(cunkuan)

.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();

}

privatevoidquitActionPerformed(ActionEventevt){load.setVisible(true);

this.setVisible(false);

}

privatevoidresetActionPerformed(ActionEventevt){setpw.setVisible(true);

this.setVisible(false);

}

privatevoidcheckedActionPerformed(ActionEventevt){dis.setVisible(true);

this.setVisible(false);

}

privatevoidqukuanActionPerformed(ActionEventevt){take.setVisible(true);

this.setVisible(false);

}

privatevoidcunkuanActionPerformed(ActionEventevt){

input.setVisible(true);

this.setVisible(false);

}

/*登录界面*/

classLoadextendsJFrame{

publicJPasswordFieldJpassword;

publicJTextFieldaccountnum;

publicJButtoncommit;

privateJLabeljL1;

privateJLabeljL2;

publicLoad(){

initComponents();

this.setLocationRelativeTo(null);

this.setVisible(true);

}

privatevoidinitComponents(){

jL1=newJLabel();

jL2=newJLabel();

accountnum=newJTextField();

commit=newJButton();

Jpassword=newJPasswordField();

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOS;E

setTitle("ATM柜员模拟程序");

setResizable(false);

jL1.setText("账号:

");

jL2.setText("密码:

");

commit.setText(”确定");

commit.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEventevt){commitActionPerformed(evt);

}

new

});

javax.swing.GroupLayoutlayout=

javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayou

t.Alignment.LEADING

.addGroup(layout.createSequentialGroup().addContainerGap(50,Short.MAX_VALUE

.addGroup(layout.createParallelGroup(javax.swing.Gr

oupLayout.Alignment.TRAILING)

.addComponent(jL1)

.addComponent(jL2))

.addGap(31,31,31)

.addGroup(layout.createParallelGroup(javax.swing.Gr

oupLayout.Alignment.LEADINGfalse)

.addComponent(Jpassword)

.addComponent(accountnum,

javax.swing.GroupLayout.DEFAULT_SIZEI43,Short.MAX_VALUE

.addGroup(layout.createSequentialGroup()

.addGap(122,122,122)

.addComponent(commit)))

.addContainerGap(72,Short.MAX_VALU)E

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING

.addGroup(layout.createSequentialGroup().addGap(85,85,85).addGroup(layout.createParallelGroup(javax.swing.GroupLayou

t.Alignment.BASELINE

.addComponent(accountnum,

javax.swing.GroupLayout.PREFERRED_SIZjavax.swing.GroupLayout.DEFAULT_SIZ,E

javax.swing.GroupLayout.PREFERRED_S)ZE

.addComponent(jL1)).addGap(41,41,41).addGroup(layout.createParallelGroup(javax.swing.GroupLayou

t.Alignment.BASELINE

.addComponent(jL2)

.addComponent(Jpassword,

javax.swing.GroupLayout.PREFERRED_SI,Zjavax.swing.GroupLayout.DEFAULT_SIZ,E

javax.swing.GroupLayout.PREFERRED_S)ZE

.addPreferredGap(javax.swing^LayoutStyle.ComponentPlacement

.RELATE72,Short.MAX_VALUE

.addComponent(commit)

.addGap(64,64,64))

);

pack();

}

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);

accountnum.setText("");Jpassword.setText("");

}

}

}

/*取款界面*/

classTakeextendsJFrame{

publicJButtonback;

publicJButtonclear;

publicJButtoncommit;

privateJLabeljL1;

publicJTextFieldjT1;

publicJButtonquit;

Stringstr="";

publicTake(){

initComponents();

this.setLocationRelativeTo(null);

this.setVisible(false);

}

privatevoidinitComponents(){

jL1=newJLabel();

jT1=newJTextField();

commit=newJButton();

back=newJButton();

quit=newJButton();

clear=newJButton();

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOS;E

jL1.setText("取款金额:

");

commit.setText("确定");commit.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventevt){commitActionPerformed(evt);

}

});

back.setText(”返回”);

back.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventevt){backActionPerformed(evt);

}

});

quit.setText("退出");

quit.addActionListener(newActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEventevt){quitActionPerformed(evt);

}

});

clear.setText("清除");

c

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1