ATM柜員機模擬程序_第1頁
ATM柜員機模擬程序_第2頁
ATM柜員機模擬程序_第3頁
ATM柜員機模擬程序_第4頁
ATM柜員機模擬程序_第5頁
已閱讀5頁,還剩27頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、阿壩師范高等??茖W校電子信息工程系課程設(shè)計ATM柜員機模擬系統(tǒng)學生姓名李 其 林專業(yè)名稱嵌 入 式班 級2011級學 號阿壩師范高等??茖W校電子信息工程系2013年6月摘 要通過設(shè)計ATM柜員模擬程序,加深自己對Java編程尤其是對Java圖形用戶界面編程的了解,將自己的學到的編程知識融會貫通,同時培養(yǎng)自身面向?qū)ο筌浖_發(fā)的思維,初步了解軟件開發(fā)的一般流程,提高用Java實際動手能力并增強自己對面向?qū)ο蟮牧私?。通過這次編程設(shè)計,加深了對Java圖形界面編程中各個模塊和組件的應用了解,以及類和類之間的關(guān)系,界面排版的處理等。設(shè)計要求是,當輸入給定的卡號和密碼(初始卡號和密碼為)時,系統(tǒng)能登錄AT

2、M柜員機系統(tǒng),用戶可以進行以下操作:(1)查詢余額:初始余額為10000元。(2)ATM取款:每次取款金額為100的倍數(shù),總額不超過5000元,支取金額不允許透支。(3)ATM存款:不能出現(xiàn)負存款。(4)修改密碼:新密碼長度不小于6位,不允許出現(xiàn)6位完全相同的情況,只有舊密碼正確,新密碼符合要求,且兩次輸入相同的情況下才可以成功修改密碼。該程序設(shè)置了7個類,1個主類6個輔助類,6個輔助類都是內(nèi)部類的形式,輔助類包括五個實現(xiàn)ATM的功能,一個存放客戶資料,之所以用內(nèi)部類來實現(xiàn)是為了在各個界面轉(zhuǎn)換時不至于要創(chuàng)建多個對象,每一個輔助類的對象只要在主類中創(chuàng)建一次就可以在各個內(nèi)部類中引用。該程序利用的功

3、能是利用Java事件監(jiān)聽技術(shù)來實現(xiàn)的,各種功能單獨的創(chuàng)建一個類來實現(xiàn),不會互相混淆,更加容易理清楚思路。設(shè)計的程序完美的實現(xiàn)了設(shè)計要求,具有查詢、取款、存款、修改密碼等功能。1 前言1.1 設(shè)計任務1.1.1 需求說明隨著市場經(jīng)濟的繁榮發(fā)展,人們的物質(zhì)生活得到極大的提高,手中的剩余資金也日益增多。受傳統(tǒng)觀念影響,絕大多數(shù)人喜歡把資金投進銀行,而在需要使用現(xiàn)金的時候再到銀行提取現(xiàn)金。這就導致銀行業(yè)務的急劇增加。雖然銀行網(wǎng)點越來越多,銀行的工作效率也隨著信息化有較明顯的增長,但是依舊不能滿足廣大用戶的需要。而一味的增加營業(yè)網(wǎng)點,從理論上雖然能稍微的緩解銀行的壓力,但是治標不治本,而且每增加一個網(wǎng)點

4、,不僅要付出昂貴的資金成本,還需要長期投入人力資本,成本非常之昂貴。這時候就迫切的需要一種自動的,易于普及的,低成本的設(shè)備來解決這一問題。于是ATM機系統(tǒng)應運而生了。本文正是通過設(shè)計一個ATM模擬模擬程序來實現(xiàn)ATM機系統(tǒng)的基本功能,充分運用自己所學的Java知識進行設(shè)計編程。1.2 設(shè)計內(nèi)容(1)程序要求 (2)算法分析 (3)流程圖 (4)源程序 (5)調(diào)試及運行結(jié)果(6)總結(jié)2 程序要求本ATM柜員機的主要功能如下所述:要求使用圖形用戶界面。當輸入給定的卡號和密碼(初始卡號和密碼為)時,系統(tǒng)能登錄ATM柜員機系統(tǒng),用戶可以按照以下規(guī)則進行:l 查詢余額:初始余額為10000元。l ATM

5、取款:每次取款金額為100的倍數(shù),總額不超過5000元,支取金額不允許透支。l ATM存款:不能出現(xiàn)負存款。l 修改密碼:新密碼長度不小于6位,不允許出現(xiàn)6位完全相同的情況,只有舊密碼正確,新密碼符合要求,且兩次輸入相同的情況下才可以成功修改密碼。3 算法分析通過程序要求,我們可以清楚的知道本次設(shè)計的ATM柜員模擬程序需要實現(xiàn)四大功能,即查詢余額、取款、存款、修改密碼。初次之外,作為ATM系統(tǒng),還需要最基本的兩大功能,即登陸和退出。根據(jù)上述的功能分析,我們可以吧整個ATM系統(tǒng)分為登陸模塊、查詢模塊、取款模塊、存款模塊、修改密碼模塊。除此之外,還有在登陸系統(tǒng)后的功能選擇模塊,退出功能則鑲嵌在各個

6、需要的模塊中。由于各個模塊的功能實現(xiàn)是通過界面顯示出來的,則程序設(shè)計又可以理解為幾大界面的設(shè)計:登陸界面、主界面、查詢余額界面、取款界面、存款界面、修改密碼界面。除了幾大界面之外,還有系統(tǒng)的初始化,主要是初始卡號、密碼的設(shè)定等。在程序的大體框架確定之后,我們需要了解各個模塊所要實現(xiàn)和需要具有的功能。根據(jù)現(xiàn)有的銀行ATM系統(tǒng),我們可以很快就可以了解本次設(shè)計的ATM系統(tǒng)應該具有的操作。(1)登陸界面用戶輸入正確的賬號和密碼就可以登錄到該系統(tǒng)的主界面中去,進行相應的操作:取款、存款、查詢、修改密碼。(2)主界面主界面包括查詢、存款、取款、修改密碼、退出的功能按鈕,按下相應的按鈕,可以進行相應的操作。

7、(3)查詢界面在主界面中按下查詢按鈕可以進行查詢操作。通過查詢功能我們可以查詢賬戶的余額,在查詢過程中我們可以選擇取款的業(yè)務,除此之外,查詢界面之中還有返回和退出的操作。返回的操作會使用戶回到主界面,退出的操作會使用戶直接回到登陸界面。(4)取款界面取款界面既可以通過主界面進入,也可以通過查詢、存款等操作過程中的界面進入。取款功能在對話框中輸入你想要取出的金額,但是次金額不可以比賬戶的余額大,且必須是100的整數(shù)倍,取款完畢,會彈出是否顯示余額的提示,選“是”的話就會進入查詢界面,選“否”的話,則回到主界面。(5)存款界面在主界面按下存款按鈕可以進行存款操作,在對話中輸入你需要存入的金額,所輸

8、入的數(shù)字也要是100的整數(shù)倍,而且不可以是負數(shù)。存款完畢,會彈出是否顯示余額的提示,選“是”的話就會進入查詢界面,選“否”的話,則回到主界面。(6)修改密碼選擇修改密碼按鈕可以進行修改密碼房,但是要先輸入就密碼正確并且兩次輸入新密碼一致才可以修改密碼。修改完成后,會返回主界面。4 流程圖圖1 程序流程圖5 程序源代碼及說明5.1 程序源代碼import javax.swing.*;import javax.swing.JOptionPane;import java.awt.event.*;class ATMmodel Account myaccount=new Account(); Load

9、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柜員模擬系統(tǒng)); public static void main(String args) ATMmodel atm=new ATMmodel(); /*創(chuàng)建賬戶*/ class A

10、ccount private int count=10000; /初始賬戶余額10000 private String account=; /初始賬號 private String password=; /初始密碼 public Account() public void setpw(String password) this.password=password; public void deccount(int money) count-=money; public void reccount(int money) count+=money; public int get() return

11、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 JButton reset; public MainFrame() initComponents(); this.setLocationR

12、elativeTo(null); / this.setVisible(false); /* 控件初始化*/ private void initComponents() cunkuan = new JButton(); qukuan = new JButton(); checked = new JButton(); reset = new JButton(); quit = new JButton();setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle(ATM柜員模擬程序);setName(mianframe); s

13、etResizable(false); cunkuan.setText(存款); cunkuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) cunkuanActionPerformed(evt); );qukuan.setText(取款); qukuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) qukuanActionPerformed(evt

14、); );checked.setText(查詢); checked.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) checkedActionPerformed(evt); );reset.setText(修改密碼); reset.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) resetActionPerformed(evt); );quit.setTex

15、t(退出); quit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) quitActionPerformed(evt); );GroupLayout layout = new GroupLayout(getContentPane(); /GroupLayout它將組件按層次分組,以決定它們在 Container 中的位置 getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createP

16、arallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(cunkuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPl

17、acement.RELATED, 105, Short.MAX_VALUE) .addComponent(reset) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(qukuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE) .addComponent(quit) .addComponent(checked)

18、 .addContainerGap() ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cunkuan) .addComponent(res

19、et) .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(); private void quitActionPerformed(ActionEvent evt) load.setVisible(true); this.s

20、etVisible(false); private void resetActionPerformed(ActionEvent evt) setpw.setVisible(true);this.setVisible(false); private void checkedActionPerformed(ActionEvent evt) dis.setVisible(true); this.setVisible(false); private void qukuanActionPerformed(ActionEvent evt) take.setVisible(true); this.setVi

21、sible(false); private void cunkuanActionPerformed(ActionEvent evt) input.setVisible(true); this.setVisible(false); /*登錄界面*/ class Load extends JFrame public JPasswordField Jpassword; public JTextField accountnum; public JButton commit; private JLabel jL1; private JLabel jL2; public Load() initCompon

22、ents(); this.setLocationRelativeTo(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柜員模擬程序)

23、; setResizable(false); 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(getConte

24、ntPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGro

25、up() .addContainerGap(50, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jL1) .addComponent(jL2) .addGap(31, 31, 31) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Jpassword) .addCo

26、mponent(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

27、) .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) .addComponen

28、t(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.L

29、ayoutStyle.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

30、ible(false);accountnum.setText();Jpassword.setText();elseJOptionPane.showMessageDialog(null,密碼與賬戶不匹配,請重新輸入,出錯提示,1);accountnum.setText();Jpassword.setText(); /*取款界面*/class Take extends JFrame public JButton back; public JButton clear; public JButton commit; private JLabel jL1; public JTextField jT1;

31、public JButton quit; String str=; public Take() initComponents(); this.setLocationRelativeTo(null); this.setVisible(false); private void initComponents() jL1 = new JLabel(); jT1 = new JTextField(); commit = new JButton(); back = new JButton(); quit = new JButton(); clear = new JButton(); setDefaultC

32、loseOperation(WindowConstants.EXIT_ON_CLOSE); jL1.setText(取款金額:); commit.setText(確定); commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt); ); back.setText(返回); back.addActionListener(new ActionListener() public void actionPerformed(Ac

33、tionEvent evt) backActionPerformed(evt); ); quit.setText(退出); quit.addActionListener(new ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) quitActionPerformed(evt); ); clear.setText(清除); clear.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e

34、vt) clearActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(41, 4

35、1, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jL1) .addGap(33, 33, 33) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequen

36、tialGroup() .addComponent(clear) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE) .addComponent(quit) .addGroup(layout.createSequentialGroup() .addComponent(commit) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE) .a

37、ddComponent(back) .addContainerGap(69, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(103, 103, 103) .addGroup(layout.createParallelGroup(javax.swing.GroupLayou

38、t.Alignment.BASELINE) .addComponent(jL1) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(61, 61, 61) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(commit)

39、 .addComponent(back) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clear) .addComponent(quit) .addContainerGap(65, Short.MAX_VALUE) ); pack(); private void clearActionPerformed(ActionEvent evt) str=; jT1.setText(str); private void

40、quitActionPerformed(ActionEvent evt) load.setVisible(true);this.setVisible(false); private void backActionPerformed(ActionEvent evt) Jmain.setVisible(true);this.setVisible(false); private void commitActionPerformed(ActionEvent evt) if(Integer.parseInt(jT1.getText()0 & Integer.parseInt(jT1.getText()%

41、100=0 & Integer.parseInt(jT1.getText()=5000) myaccount.deccount(Integer.parseInt(jT1.getText(); int result=javax.swing.JOptionPane.showConfirmDialog(null,是否顯示余額?,javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE); if(result=javax.swing.JOptionPane.YES_OPTION) dis.set(Str

42、ing.valueOf(myaccount.get(); str=; jT1.setText(str); dis.setVisible(true); this.setVisible(false); else Jmain.setVisible(true); this.setVisible(false); else JOptionPane.showMessageDialog(null,取款金額不能為負數(shù)+n取款金額不能為0+n取款金額必須是100的倍數(shù)+n金額一次不能超過5000+n請重新輸入你要取的金額數(shù),出錯提示,1); str=; jT1.setText(str); /*存款界面*/clas

43、s Input extends JFrame private JButton clear; private JButton commit; private JLabel jL1; private JTextField 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(WindowConstants.EXIT_ON_CLOSE); jL1.setText(存款金額:); commit.setText(確認); commit.addActionListener(new Actio

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論