使用Java语言进行面向对象设计:ATM柜员机模拟程序
要求:使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:(1)查询余额功能:初始余额为10...
要求:使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
(1)查询余额功能:初始余额为10000元
(2)ATM取款功能:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
(3)ATM存款功能:不能出现负存款。
(4)修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
没分了 那个朋友帮个忙吧 展开
(1)查询余额功能:初始余额为10000元
(2)ATM取款功能:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
(3)ATM存款功能:不能出现负存款。
(4)修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
没分了 那个朋友帮个忙吧 展开
1个回答
展开全部
import java.awt.*;
import java.awt.event.*;
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密码错误,请重新输入:";
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);
area1Panel.add(note);
buttonPanel.setLayout(new GridLayout(4,4));
for(int count=0;count<buttons.length;count++)
{
buttons[count]=new JButton(""+count);
buttons[count].addActionListener(this);
buttonPanel.add(buttons[count]);
}
buttonPanel.add(doublezero);
buttonPanel.add(dot);
buttonPanel.add(change);
buttonPanel.add(cancel);
buttonPanel.add(ok);
buttonPanel.add(exit);
container.add(buttonPanel,BorderLayout.SOUTH);
container.add(area1Panel);
area1Panel.setVisible(true);
area2Panel.setVisible(false);
setSize(400,250);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JButton operation = (JButton) event.getSource();
if(operation==ok)
{
if(status==0)
{
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);
store2="";
}
else if(status==3)
{
if(flag0==true)
{
getMoney=Double.valueOf(store1).doubleValue();
if(getMoney<moneysum)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag0=false;
moneysum=moneysum-getMoney;
}
else
{
area2Panel.setVisible(false);
area1Panel.setVisible(true);
note.setText(""+str10);
store1="";
}
}
else if(flag1==true)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag1=false;
}
else if(flag2==true)
flag2=false;
else if(flag3=true)
{
flag4=true;
note.setText(""+str11);
password=store2;
flag3=false;
}
}
}
else if(operation==cancel)
{
if(status==1)
{
note.setText(""+str1);
status=0;
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str2);
status=1;
store1="";
store2="";
}
else if(status==3&&flag2)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag2=false;
store1="";
store2="";
}
else if(status==3&&flag0)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag0=false;
store1="";
store2="";
}
else if(status==3&&flag3)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag3=false;
store1="";
store2="";
}
}
else if(operation==change)
{
if(status==1)
{
note.setText(""+str2);
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str3);
store1="";
store2="";
}
else if(status==3&&flag2)
{
note.setText(""+str5);
store1="";
store2="";
}
else if(status==3&&flag0)
{
note.setText(""+str4);
store1="";
store2="";
}
else if(status==3&&flag3)
{
note.setText(""+str6);
store1="";
store2="";
}
}
else if(operation==doublezero&&status==3&&flag0==true)
{
note.setText(note.getText()+"00");
}
else if(operation==dot&&status==3&&flag0==true)
{
note.setText(note.getText()+".");
}
else if(operation==getmoney)
{
note.setText(""+str4);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store1="";
flag0=true;
}
else if(operation==search)
{
note.setText(""+str7+moneysum);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag1=true;
}
else if(operation==putmoney)
{
note.setText(""+str5);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag2=true;
}
else if(operation==changekey)
{
note.setText(""+str6);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store2="";
flag3=true;
}
else if(operation==exit)
{
note.setText(""+str1);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
status=0;
flag0=flag1=flag2=flag3=flag4=false;
store1="";
store2="";
k=k1=s=0;
}
else if(status==1||(status==3&&flag2==true)||(status==3&&flag0==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText() + count);
store1+=event.getActionCommand();
}
user(store1);
}
else if(status==2||(status==3&&flag3==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText()+ "*");
store2+=event.getActionCommand();
}
key(store2);
}
}
public void user(String load)
{
if(username.equals(load))
{
k=1;
s=1;
}
}
public void key(String load)
{
if(password.equals(store2))
{
k1=1;
}
}
public static void main(String args[])
{
AtmSystem application=new AtmSystem();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.event.*;
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密码错误,请重新输入:";
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);
area1Panel.add(note);
buttonPanel.setLayout(new GridLayout(4,4));
for(int count=0;count<buttons.length;count++)
{
buttons[count]=new JButton(""+count);
buttons[count].addActionListener(this);
buttonPanel.add(buttons[count]);
}
buttonPanel.add(doublezero);
buttonPanel.add(dot);
buttonPanel.add(change);
buttonPanel.add(cancel);
buttonPanel.add(ok);
buttonPanel.add(exit);
container.add(buttonPanel,BorderLayout.SOUTH);
container.add(area1Panel);
area1Panel.setVisible(true);
area2Panel.setVisible(false);
setSize(400,250);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JButton operation = (JButton) event.getSource();
if(operation==ok)
{
if(status==0)
{
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);
store2="";
}
else if(status==3)
{
if(flag0==true)
{
getMoney=Double.valueOf(store1).doubleValue();
if(getMoney<moneysum)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag0=false;
moneysum=moneysum-getMoney;
}
else
{
area2Panel.setVisible(false);
area1Panel.setVisible(true);
note.setText(""+str10);
store1="";
}
}
else if(flag1==true)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag1=false;
}
else if(flag2==true)
flag2=false;
else if(flag3=true)
{
flag4=true;
note.setText(""+str11);
password=store2;
flag3=false;
}
}
}
else if(operation==cancel)
{
if(status==1)
{
note.setText(""+str1);
status=0;
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str2);
status=1;
store1="";
store2="";
}
else if(status==3&&flag2)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag2=false;
store1="";
store2="";
}
else if(status==3&&flag0)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag0=false;
store1="";
store2="";
}
else if(status==3&&flag3)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag3=false;
store1="";
store2="";
}
}
else if(operation==change)
{
if(status==1)
{
note.setText(""+str2);
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str3);
store1="";
store2="";
}
else if(status==3&&flag2)
{
note.setText(""+str5);
store1="";
store2="";
}
else if(status==3&&flag0)
{
note.setText(""+str4);
store1="";
store2="";
}
else if(status==3&&flag3)
{
note.setText(""+str6);
store1="";
store2="";
}
}
else if(operation==doublezero&&status==3&&flag0==true)
{
note.setText(note.getText()+"00");
}
else if(operation==dot&&status==3&&flag0==true)
{
note.setText(note.getText()+".");
}
else if(operation==getmoney)
{
note.setText(""+str4);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store1="";
flag0=true;
}
else if(operation==search)
{
note.setText(""+str7+moneysum);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag1=true;
}
else if(operation==putmoney)
{
note.setText(""+str5);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag2=true;
}
else if(operation==changekey)
{
note.setText(""+str6);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store2="";
flag3=true;
}
else if(operation==exit)
{
note.setText(""+str1);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
status=0;
flag0=flag1=flag2=flag3=flag4=false;
store1="";
store2="";
k=k1=s=0;
}
else if(status==1||(status==3&&flag2==true)||(status==3&&flag0==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText() + count);
store1+=event.getActionCommand();
}
user(store1);
}
else if(status==2||(status==3&&flag3==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText()+ "*");
store2+=event.getActionCommand();
}
key(store2);
}
}
public void user(String load)
{
if(username.equals(load))
{
k=1;
s=1;
}
}
public void key(String load)
{
if(password.equals(store2))
{
k1=1;
}
}
public static void main(String args[])
{
AtmSystem application=new AtmSystem();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询