JAVA 程序设计课程设计报告
设计题目: ATM 柜员模拟程序
专
班
学
业 计算机科学与技术
级 计科(103)班
号
学生姓名
指导教师
设计时间 2011-2012 学年上学期
教师评分
2011 年 12 月 12 日
1
目 录
(写完内容后生成目录)
1.概述 ..................................................................................................................1
1.1 目的......................................................................................................... 1
1.2 课程设计的组成部分............................................................................. 2
2. ATM 柜员模拟程序设计的内容:.................................................................. 2
3.总结................................................................................................................. 20
3.1 课程设计进行过程及步骤:............................................................... 20
3.2 所遇到的问题,你是怎样解决这些问题的:................................... 20
3.3 体会收获及建议:............................................................................... 20
3.4 参考资料............................................................................................... 20
4.教师评语......................................................................................................... 20
5.成绩................................................................................................................. 21
(课程设计需填写的内容包括):
1.概述
1.1 目的:通过对程序的编辑。明白和掌握 JAVA 语言的魅力。并且掌握 JAVA 的知识能够
熟练的应用 JAVA 这门语言。会编辑程序。
1
1.2 课程设计的组成部分:源代码,运行的结果和图片。
ATM 柜员模拟程序设计的内容:
ATM
的
主
类
:
AtmSystem extends JFrame
implements ActionListener
public
void
actionPerfor
med(ActionEv
Public
user(String load)
void
ent event)
void
public
key(String
load)ent event)
public static void
main(String
args[])ent event)
ATM 柜员机模拟程序
功能要求:使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码
为 123456 时),系统能登陆 ATM 柜员机系统。用户可以按照以下规划进行:
查询余额,初始余额为 10000 元
ATM 取款:每次取款金额为 100 的倍数,总额不超过 5000 元,支取金
额不允许透支
ATM 存款:不允许出现负存款
修改密码:新密码长度不小于 6 位,不允许出现 6 位完全相同的情况,
只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以修
改成功
import java.awt.*;
import java.awt.event.*;
2
import javax.swing.*;
public class AtmSystem extends JFrame
implements ActionListener
{
private JPanel buttonPanel=new JPanel();
private JPanel area1Panel=new JPanel();
private JPanel area2Panel=new JPanel();
private JTextField note=new JTextField(33);
private JButton buttons[];
private JButton dot = new JButton(".");
private JButton doublezero = new JButton("00");
private JButton ok = new JButton("确定");
private JButton exit = new JButton("退出");
private JButton cancel = new JButton("取消");
private JButton change=new JButton("更正");
private JButton getmoney = new JButton("取款");
private JButton search = new JButton("查询余额");
private JButton changekey = new JButton("修改密码");
private JButton putmoney= new JButton("存款");;
private boolean flag0, flag1, flag2,flag3,flag4;
int status=0;
int k,s,k1;
String str1="\t 欢迎使用 ATM 柜员机!";
String str2="\t 请输入用户名:";
String str3="\t 请输入密码:";
String str4="\t 请输入取款金额:";
String str5="\t 请输入存款金额:";
String str6="\t 请输入新密码:";
String str7="\t 您的余额为:";
String str8="\t 用户名错误,请重新输入:";
String str9="\t 密码错误,请重新输入:";
3
String str10="\t 余额不足,请重新输入:";
String str11="\t 密码修改成功!";
String store1="",store2="";
double moneysum=10000;
double getMoney;
String
username="123456";
String password="123456";
public AtmSystem()
{
super("ATM 柜员机");
Container container=getContentPane();
buttons=new JButton[10];
dot.addActionListener(this);
doublezero.addActionListener(this);
change.addActionListener(this);
cancel.addActionListener(this);
ok.addActionListener(this);
exit.addActionListener(this);
changekey.addActionListener(this);
putmoney.addActionListener(this);
getmoney.addActionListener(this);
search.addActionListener(this);
area2Panel.add(changekey);
area2Panel.add(putmoney);
area2Panel.add(getmoney);
area2Panel.add(search);
area2Panel.setLayout(new GridLayout(1,3));
container.add(area2Panel,BorderLayout.NORTH);
note.setText(str1);
note.setEditable(false);
4
area1Panel.add(note);
buttonPanel.setLayout(new GridLayout(4,4));
for(int count=0;count
note.setText(""+str2);
status=1;
}
else if(flag4==true)
{
}
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag4=false;
else if(status==1&&k==1)
{
}
note.setText(""+str3);
status=2;
k=0;
else if(status==1&&k==0)
{
}
note.setText(""+str8);
store1="";
else if(status==2&&k1==1)
{
}
k1=0;
area1Panel.setVisible(false);
area2Panel.setVisible(true);
status=3;
else if(status==2&&k1==0)
{
note.setText(""+str9);
6
store2="";
}
else if(status==3)
{
{
if(flag0==true)
getMoney=Double.valueOf(store1).doubleValue();
if(getMoney