《Java程序.doc》由会员分享,可在线阅读,更多相关《Java程序.doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、 网页 图片 视频 音乐 问问 百科 新闻 地图 更多 登录 搜搜问问窗体顶端窗体底端 问问首页 问题库 知识频道 用户频道 问问活动 问问团队 问问商城 电脑/数码 生活家居 QQ专区 游戏 奥运体育 娱乐/明星 休闲/爱好 艺术/文学 社会/人文 教育/科学 健康/医疗 商业/理财 情感/家庭 地区问题 全部问题 电脑/数码编程 分享: 腾讯微博 QQ空间 新浪微博 | 收藏 Evolution 2009-04-21 谁帮我用JAVA写一个简单的模拟ATM的程序谁帮我用JAVA写一个简单的模拟ATM的程序最好要有思路,或直接给个网站也行.谢谢了 满意答案Sy.Memoryer 3级 200
2、9-04-21 public class BankSys /private int uId; /这写好像用不上,你自己看着加吧 /private String uName;/private String address;private double minMon=0.50;private double money=1000.50;public static void main(String args) String answer;System.out.println(欢迎进入存取款系统!);System.out.println(-);doSystem.out.println(1.取款 t2.查
3、询余额t3.存款);Scanner sc=new Scanner(System.in);BankSys bank=new BankSys();int num=sc.nextInt();switch (num) case 1:bank.get();break;case 2:bank.search();break;case 3:bank.deposit();break;default:break;System.out.println(是否继续?(y/n));answer=sc.next();while(answer.equals(y);System.out.println(程序结束);public
4、 void deposit()Scanner sc=new Scanner(System.in);System.out.println(请输入存款金额:);double input=sc.nextInt();System.out.println(您的帐户原有余额为:+money+元);System.out.println(已存入:+input+元);money+=input;System.out.println(您的帐户最终存款余额为:+money+元);public void search()System.out.println(您的帐户余额为:+money+元);public void g
5、et()Scanner sc=new Scanner(System.in);System.out.println(请输入取款金额:);double input=sc.nextInt();if (moneyjava模拟atm查询余模拟atm柜员机程序atm取款机java程序atm程序 java用java写atm界面代atm是什么意思java atm取款机系统java程序Top何夏冰 随风 安靜聽 助提意见 5.1 程序源代码 import javax.swing.*; import javax.swing.JOptionPane; import java.awt.event.*; public
6、class ATMmodel Account myaccount=new Account(); Load load=new Load(); MainFrame Jmain=new MainFrame(); Take take=new Take(); Input input=new Input(); Display dis=new Display(); Setpw setpw=new Setpw(); public ATMmodel() JOptionPane.showMessageDialog(null,欢迎使用ATM柜员模拟系统); public static void main(Strin
7、g args) ATMmodel atm=new ATMmodel(); /*创建账户*/ class Account private int count=10000; /初始账户余额10000 private String account=123456; /初始账号 private String password=123456; /初始密码 public Account() public void setpw(String password) this.password=password; public void deccount(int money) count-=money; publi
8、c void reccount(int money) count+=money; public int get() return count; public String getaccount() /账号 return account; public String getpw() return password; /* 主界面*/ class MainFrame extends JFrame public JButton checked; public JButton cunkuan; public JButton quit; public JButton qukuan; public JBu
9、tton reset; public MainFrame() initComponents(); this.setLocationRelativeTo(null); / this.setVisible(false); /* 控件初始化*/ private void initComponents() cunkuan = new JButton(); qukuan = new JButton(); checked = new JButton(); reset = new JButton(); quit = new JButton(); setDefaultCloseOperation(Window
10、Constants.EXIT_ON_CLOSE); setTitle(ATM柜员模拟程序); setName(mianframe); setResizable(false); cunkuan.setText(存款); cunkuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) cunkuanActionPerformed(evt); ); 面向对象课程设计ATM柜员机模拟程序 6 qukuan.setText(取款); qukuan.addActionListener(n
11、ew ActionListener() public void actionPerformed(ActionEvent evt) qukuanActionPerformed(evt); ); checked.setText(查询); checked.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) checkedActionPerformed(evt); ); reset.setText(修改密码); reset.addActionListener(new ActionList
12、ener() public void actionPerformed(ActionEvent evt) resetActionPerformed(evt); ); quit.setText(退出); quit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) quitActionPerformed(evt); ); GroupLayout layout = new GroupLayout(getContentPane(); /GroupLayout它将组件按层次分组,以决定它们
13、在 Container 中的位置 getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.creat
14、eSequentialGroup() .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.LayoutStyl
15、e.ComponentPlacement.RELATED, 143, Short.MAX_VALUE) .addComponent(quit) 面向对象课程设计ATM柜员机模拟程序 8 /*登录界面*/ class Load extends JFrame public JPasswordField Jpassword; public JTextField accountnum; public JButton commit; private JLabel jL1; private JLabel jL2; public Load() initComponents(); this.setLocati
16、onRelativeTo(null); this.setVisible(true); private void initComponents() jL1 = new JLabel(); jL2 = new JLabel(); accountnum = new JTextField(); commit = new JButton(); Jpassword = new JPasswordField(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle(ATM柜员模拟程序); setResizable(false);
17、 jL1.setText(账号:); jL2.setText(密码:); commit.setText(确定); commit.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) commitActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPa
18、ne().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(
19、50, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jL1) .addComponent(jL2) .addGap(31, 31, 31) 面向对象课程设计ATM柜员机模拟程序 9 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Jpassword) .addCom
20、ponent(accountnum, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(122, 122, 122) .addComponent(commit) .addContainerGap(72, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
21、 .addGroup(layout.createSequentialGroup() .addGap(85, 85, 85) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(accountnum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent
22、(jL1) .addGap(41, 41, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jL2) .addComponent(Jpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.La
23、youtStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE) .addComponent(commit) .addGap(64, 64, 64) ); pack(); private void commitActionPerformed(ActionEvent evt) if(accountnum.getText().equals(myaccount.getaccount() & Jpassword.getText().equals(myaccount.getpw() Jmain.setVisible(true); this.setVis
24、ible(false); accountnum.setText(); Jpassword.setText(); else JOptionPane.showMessageDialog(null,密码与账户不匹配,请重新输入,出错提示,1); 面向对象课程设计ATM柜员机模拟程序 12 .BASELINE) .addComponent(commit) .addComponent(back) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .add
25、Component(clear) .addComponent(quit) .addContainerGap(65, Short.MAX_VALUE) ); pack(); private void clearActionPerformed(ActionEvent evt) str=; jT1.setText(str); private void quitActionPerformed(ActionEvent evt) load.setVisible(true); this.setVisible(false); private void backActionPerformed(ActionEve
26、nt evt) Jmain.setVisible(true); this.setVisible(false); private void commitActionPerformed(ActionEvent evt) if(Integer.parseInt(jT1.getText()0 & Integer.parseInt(jT1.getText()%100=0 & Integer.parseInt(jT1.getText()=5000) myaccount.deccount(Integer.parseInt(jT1.getText(); int result=javax.swing.JOpti
27、onPane.showConfirmDialog(null,是否显示余额?,javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE); if(result=javax.swing.JOptionPane.YES_OPTION) dis.set(String.valueOf(myaccount.get(); str=; jT1.setText(str); dis.setVisible(true); this.setVisible(false); else Jmain.setVisible(tru
28、e); 面向对象课程设计ATM柜员机模拟程序 13 this.setVisible(false); else JOptionPane.showMessageDialog(null,取款金额不能为负数+n取款金额不能为0+n取款金额必须是100的倍数+n金额一次不能超过5000+n请重新输入你要取的金额数,出错提示,1); str=; jT1.setText(str); /*存款界面*/ class Input extends JFrame private JButton clear; private JButton commit; private JLabel jL1; private JTe
29、xtField jT1; String str=; public Input() initComponents(); this.setLocationRelativeTo(null); this.setResizable(false); this.setVisible(false); private void initComponents() jL1 = new JLabel(); jT1 = new JTextField(); commit = new JButton(); clear = new JButton(); setDefaultCloseOperation(WindowConst
30、ants.EXIT_ON_CLOSE); jL1.setText(存款金额:); commit.setText(确认); commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt); ); clear.setText(清除); clear.addActionListener(new java.awt.event.ActionListener() 面向对象课程设计ATM柜员机模拟程序 17 ); javax.swing.G
31、roupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jL1) .addPreferredGap(java
32、x.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(36, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, l
33、ayout.createSequentialGroup() .addContainerGap(215, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(back) .addComponent(qukuan) .addComponent(quit) .addContainerGap() ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.Gr
34、oupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(93, 93, 93) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jL1) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.G
35、roupLayout.PREFERRED_SIZE) .addGap(54, 54, 54) .addComponent(qukuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(back) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(quit) .addContainerGap() ); pack(); 面向对象课程设计ATM柜员机模拟程序 18 private void qukuanActionPerformed(ActionEvent evt) take.setVisible(true); this.setVisible(false); private void quitActionPerformed(ActionEvent evt) load.setVisible(true); this.setVisible(false); private void backActionPe