java课程设计(ATM机).doc_第1页
java课程设计(ATM机).doc_第2页
java课程设计(ATM机).doc_第3页
java课程设计(ATM机).doc_第4页
java课程设计(ATM机).doc_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

目 录1 前言12 需求分析12.1 任务和要求12.2 运行环境12.3 开发工具13 分析和设计23.1 系统分析及设计思路23.2 主要类图24 具体代码实现55 课程设计总结55.1 程序运行结果或预期运行结果165.2 设计结论16参考文献20致 谢211 前言本次的课程设计,主要是编写一个程序来管理ATM机模拟系统。ATM机模拟系统主要是由各个Windows窗口组成,它是由登录页面、选择服务、存款、取款、查询余额、修改密码和退卡等功能。它的各种按钮的事件和功能可以简单的模拟ATM机系统的要求。2 需求分析2.1 任务和要求设计一个ATM机模拟系统。要求:可以登录ATM柜员机系统,用户可以按照以下规则进行:查询余额:初始余额为50000元;ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支;ATM存款:不能出现负存款;修改密码:只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。以Windows窗口形式显示,标题栏为ATM机名称,右上角有最小化按钮、最大化按钮、关闭按钮,不同的窗口中有不同的按钮和选择菜单。2.2 运行环境(1)WINDOWS7/XP系统(2)myeclipse2.3 开发工具Java 3 分析和设计3.1 系统分析及设计思路ATM机模拟系统主要是由登录页面模块还由选择服务模块组成,其中选择服务模块又由存款模块、取款模块、查询余额模块、修改密码模块、退卡模块组成。登录页面模块:我们对于ATM机最关心的是安全问题,当然是密码,所以第一个界面就是要输入密码和卡号才能继续服务。首先定义了文本框类的对象tf1,tf2,用于输入单行的文本;调用public String getPassword()方法,获取用户想要的字符串;判断输入的密码和卡号是否正确,如果不正确的话,则弹出密码或卡号错误的警告框,并用dispose()关掉窗口。定义一个Account类来实现这一功能。选择服务模块:在选择服务模块中,有各种ATM的服务功能,只要用户在该界面中选择按钮,它就会弹出各个相应的界面。每一个按钮都有监听器,在选择了按钮后,java.awt.event中的ActionEvent类创建一个事件对象,并将它传递给方法public void actionPerformed(ActionEvent e)中的参数e,监视器就会知道所发生的事件,对此事件进行处理。定义一个Selection类来实现这一功能。其中部分代码:p.add(new Label(请选择你要的服务);this.add(p); /*各种服务功能*/buttonCUN = new Button( 存 款 );p1.add(buttonCUN);this.add(p1);buttonQU = new Button( 取 款 );p2.add(buttonQU);this.add(p2);buttonCHA = new Button( 查询余额 );p3.add(buttonCHA);this.add(p3);buttonGAI = new Button( 修改密码 );p4.add(buttonGAI);this.add(p4);buttonTUI = new Button( 退 出 );p5.add(buttonTUI);this.add(p5);存款模块:在存款模块中,有一个文本框和一个按钮还有标签组成的。用户在文本框中输入他想存的数额,但是必须是100的倍数且是正整数。否则就会弹出报错的窗口。定义一个SetBalance类来实现这一功能。取款模块:在取款模块中,也是有一个文本框和一个按钮还有标签组成的。用户在文本框中输入他想取的数额,但是必须是100的倍数,而且每一次最多只能取5000元块。当然了取款的时候也不能超过卡里的余额,再就是卡里的余额不可以为负,否则就会弹出报错的窗口。定义一个GetBalance类来实现这一功能。部分代码为:public String withdrawMoney(double money)String str = null ; if(money=0) str = 取款数目须是正数!; else if(getMoney()0)/判断余额是否为负 str=余额为负数!; else if(money=5000)/取钱数为100的倍数或不大于5000 str= 取款数目须是一百的整数倍!; else setBalance(money); str = 取款成功:余额为+getMoney(); else str = 余额不足!; return str ;查询余额模块:,运用panel1.add(new Label(你的余额为: + act.getMoney();方法来查询的你余额,余额可以是任何格式的,没有要求限制。定义了一个Query类来实现这一功能。修改密码模块:在修改密码模块中,首先你必须要输入你的旧密码是否正确,否则就会报错。再一个就是要两次输入你的新密码,且两次要匹配,否则也会报错,然后再重新回到修改密码的界面。定义了一个ChangePassword类,来实现这一功能。退卡模块:在退卡模块设计中,只是用了if(e.getSource()=buttonTUI)/退出System.exit(0);dispose();这个方法就可以实现了。3.2 主要类图图3.1 机模拟系统类图4 具体代码实现(主要源代码)Account类package com.syxy.kcsj.account; /* * 帐户 * 该类为实现客户信息及部分功能 */public class Account private String code = null; /信用卡号private String name = null; /客户姓名private String password= null; /客户密码private double money = 0.0; /卡里金额public Account()this.code = 123456 ;this.password = 123456 ;public Account(String code,String name,String password,double money) this.code=code; =name;this.password=password;this.money=money; public String getCode() /取得卡号return code; public String getName() /取得名字return name;/* * 取得密码 * return */public String getPassword() return password;/* * 重置秘密的方法 */public void changePassword(String pwd)password = pwd; public double getMoney()/取得余额return money;/* * 得到剩余的钱的数目 */private void setBalance(double mon) money -= mon;/* * 取款设置 * 若成功显示余额 * 不成功显示提示信息 */public String withdrawMoney(double money)String str = null ; if(money=0) str = 取款数目须是正数!; else if(getMoney()0)/判断余额是否为负 str=余额为负数!; else if(money5000)/取钱数为100的倍数或不大于5000 str= 取款数目须是一百的整数倍且不大于5000!; elsesetBalance(money); str = 取款成功:余额为+getMoney(); else str = 余额不足!; return str ;/* * 存款设置 * 若成功显示余额 * 不成功显示提示信息 */public String depositMoney(double money)String str = null ;if(money0)|(money%100!=0)|(money=100)str =存款数目须是正数且是一百的倍数!;elsesetBalance(-money);str = 存款成功:余额为+getMoney();return str ;WindowBox 类package com.syxy.kcsj.WindowBox;import javax.swing.*;import com.syxy.kcsj.Selection.Selection;import com.syxy.kcsj.account.Account;import java.awt.*;import java.awt.event.*; /* * 登陆页面首窗口 */SuppressWarnings(serial)public class WindowBox extends Frame implements ActionListenerBox baseBox,box1,box2; TextField tf1;JPasswordField tf2; Button button1; Button button2;public WindowBox(String s)/构造方法 super(s); tf1 = new TextField(6); tf2 = new JPasswordField(6);box1= Box.createVerticalBox();box1.add(new Label(请输入您的卡号); /输入卡号box1.add(Box.createVerticalStrut(8);box1.add(new Label(请输入您的密码);/输入密码box2=Box.createVerticalBox();box2.add(tf1);box2.add(Box.createVerticalStrut(8);box2.add(tf2);baseBox=Box.createHorizontalBox();baseBox.add(box1); baseBox.add(Box.createHorizontalStrut(10); baseBox.add(box2);add(baseBox);button1= new Button(确定);/加入按钮button1.addActionListener(this);add(button1);button2 = new Button(退卡);/退卡按钮button2.addActionListener(this);add(button2);setLayout(new FlowLayout();/*监听器*/this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););setBounds(120,125,300,200);setVisible(true); public void actionPerformed(ActionEvent e)Account act;act=new Account(000000,kcsj,123456,50000);/初始化 /*选择各种服务*/if(e.getSource() = button1)String number1,number2;/输入的两个卡号和密码的变量number1=tf1.getText().toString();number2 = new String(tf2.getPassword() ;/*判断两次输入的卡号和密码是否正确*/if(act.getCode().equals(number1)&(act.getPassword().equals(number2)dispose();new Selection(选择服务,act);elseJOptionPane.showMessageDialog(this, 密码或帐号错误!,账户提示信息,JOptionPane.ERROR_MESSAGE );dispose();new WindowBox(ATM) ;if(e.getSource()=button2)System.exit(0); dispose();/退出 Query类package com.syxy.kcsj.Query;import java.awt.*;import java.awt.event.*;import com.sun.mail.imap.ACL;import com.syxy.kcsj.Selection.Selection;import com.syxy.kcsj.account.Account;SuppressWarnings(serial)public class Query extends Frame implements ActionListenerButton button;Account act;public Query(String s,Account act)/构造函数super(s);this.act = act;button=new Button(确定);Panel panel1 = new Panel(); Panel panel = new Panel();panel1.add(new Label(你的余额为: + act.getMoney();/查询余额的方法this.add(panel1); this.add(panel); button.addActionListener(this);panel.add(button);this.setLayout(new GridLayout(2,1);this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););setBounds(200,200,200,150); setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource()=button)dispose(); new Selection(选择服务,act);/返回选择服务窗口 GetBalance 类package com.syxy.kcsj.GetBalance;import com.syxy.kcsj.Selection.Selection;import com.syxy.kcsj.account.Account;import javax.swing.*;import java.awt.*;import java.awt.event.*;SuppressWarnings(serial)public class GetBalance extends Frame implements ActionListenerBox baseBox, box1,box2;Button button;TextField tf; Account act;public GetBalance(String s,Account act)/构造函数super(s); this.act=act; button=new Button(确定);Panel panel = new Panel();Panel panel1 = new Panel();tf = new TextField(6);this.setLayout(new GridLayout(2,1);panel1.add(new Label(请输入你想取钱的数目);panel1.add(tf); panel.add(button);this.add(panel1); this.add(panel);button.addActionListener(this);this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););setBounds(200,200,300,200);this.setVisible(true);public void actionPerformed(ActionEvent e)double money; String str = null ;/* * 取款判定 */if(tf.getText().toString().equals()str = 取款数目不能为空! ;elsemoney = Double.parseDouble(tf.getText().toString();str = act.withdrawMoney(money); JOptionPane.showMessageDialog(this, str,取款提示信息,JOptionPane.INFORMATION_MESSAGE);dispose();this.setVisible(false); new Selection(选择服务,act); SetBalance 类package com.syxy.kcsj.SetBalance;import javax.swing.*;import com.syxy.kcsj.Selection.Selection;import com.syxy.kcsj.account.Account;import java.awt.*;import java.awt.event.*;SuppressWarnings(serial)public class SetBalance extends Frame implements ActionListenerBox baseBox, box1,box2;Button button;TextField tf; Account act;public SetBalance(String s,Account act)/构造函数super(s); this.act=act; button=new Button(确定);Panel panel = new Panel();Panel panel1 = new Panel();tf = new TextField(6); this.setLayout(new GridLayout(2,1);panel1.add(new Label(请输入你想存款的数目);panel1.add(tf); panel.add(button);this.add(panel1);this.add(panel);button.addActionListener(this);this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););setBounds(200,200,300,200);this.setVisible(true);public void actionPerformed(ActionEvent e)double money;String str = null ;if(tf.getText().toString().equals()str = 存款数目不能为空! ;elsemoney = Double.parseDouble(tf.getText().toString();str = act.depositMoney(money) ;JOptionPane.showMessageDialog(this, str,存款提示信息,JOptionPane.INFORMATION_MESSAGE );dispose();this.setVisible(false); new Selection(选择服务,act); Selection 类package com.syxy.kcsj.Selection;import java.awt.*;import java.awt.event.*;import com.syxy.kcsj.GetBalance.GetBalance;import com.syxy.kcsj.Query.Query;import com.syxy.kcsj.SetBalance.SetBalance;import com.syxy.kcsj.account.Account;import com.syxy.kcsj.frameui.ChangePassword;SuppressWarnings(serial)public class Selection extends Frame implements ActionListenerButton buttonCUN,buttonQU,buttonCHA,buttonTUI,buttonGAI;Panel p1 = new Panel();Panel p2 = new Panel();Panel p3 = new Panel();Panel p4 = new Panel();Panel p5 = new Panel();Panel p = new Panel();Account act;public Selection()public Selection(String s,Account act)super(s); this.act=act; this.setLayout(null);this.setLayout(new GridLayout(6,1);p.add(new Label(请选择你要的服务);this.add(p); /*各种服务功能*/buttonCUN = new Button( 存 款 );p1.add(buttonCUN); this.add(p1);buttonQU = new Button( 取 款 );p2.add(buttonQU);this.add(p2);buttonCHA = new Button( 查询余额 );p3.add(buttonCHA);this.add(p3);buttonGAI = new Button( 修改密码 );p4.add(buttonGAI);this.add(p4);buttonTUI = new Button( 退 出 );p5.add(buttonTUI);this.add(p5);this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););buttonCUN.addActionListener(this);buttonQU.addActionListener(this);buttonCHA.addActionListener(this);buttonTUI.addActionListener(this);buttonGAI.addActionListener(this);setBounds(150,150,300,200);setVisible(true);validate();public void actionPerformed(ActionEvent e)if(e.getSource()=buttonCUN)/存款dispose() ;new SetBalance(存款,act);else if(e.getSource()=buttonQU)/取款dispose();new GetBalance(取款,act);else if(e.getSource()=buttonCHA)/查询余额dispose();new Query(查询余额,act);else if(e.getSource()=buttonGAI)/修改密码dispose();new ChangePassword(修改密码,act);else if(e.getSource()=buttonTUI)/退出System.exit(0);dispose(); ChangePassword类package com.syxy.kcsj.frameui;import javax.swing.*;import com.syxy.kcsj.Selection.Selection;import com.syxy.kcsj.account.Account;import java.awt.*;import java.awt.event.*;SuppressWarnings(serial)public class ChangePassword extends Frame implements ActionListenerPanel panel1 = new Panel();Panel panel2 = new Panel();Panel panel3 = new Panel();Panel panel = new Panel();JPasswordField tf4,tf5,tf6;Button button;Account act;public ChangePassword(String s,Account act)super(s);this.act=act;tf4 = new JPasswordField(6);tf5 = new JPasswordField(6); tf6 = new JPasswordField(6);button = new Button(确定);button.addActionListener(this);/*建立新密码*/panel1.add(new Label(请输入你的旧密码:);panel1.add(tf4);panel2.add(new Label(请输入你的新密码:);panel2.add(tf5);panel3.add(new Label(请再次输入新密码:);panel3.add(tf6);panel.add(button);this.add(panel1);this.add(panel2);this.add(panel3);this.add(panel);setLayout(new GridLayout(4,1); setBounds(200,200,300,200);this.setVisible(true);/* 窗口事件, 判断窗口是否关闭*/this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0);); /* 判断事件源,看条件是否成立再修改密码*/public void actionPerformed(ActionEvent e)if(e.getSource()=button)String pwd2,pwd3,pwd4,pwd1;char p2,p3,p4;pwd1 = act.getPassword();p2=tf4.getPassword();p3=tf5.getPassword(); p4=tf6.getPassword();pwd2 = new String(p2); pwd3 = new String(p3); pwd4 = new String(p4);if(pwd2.equals(pwd1)if(pwd3.equals(pwd4)/判断两次输入的新密码是个匹配act.changePassword(pwd3);/启用新的密码dispose();JOptionPane.showMessageDialog(this, 修改密码成功!);new Selection(选择,act);/返回选择服务窗口elsethis.setVisible(true); dispose(); JOptionPane.showMessageDialog(this, 两次输入要修改的密码不同,更新密码失败!); new Selection(选择,act); elsethis.setVisible(false);dispose();JOptionPane.showMessageDialog(this, 输入密码错误,更新密码失败!); new Selection(选择,act); ATM类package com.syxy.kcsj.WindowBox;public class ATM /* * 主测试程序 * param args */public static void main(String args) new WindowBox(ATM); 5 课程设计总结5

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论