JAVA課程設計-超市收銀系統_第1頁
JAVA課程設計-超市收銀系統_第2頁
JAVA課程設計-超市收銀系統_第3頁
JAVA課程設計-超市收銀系統_第4頁
JAVA課程設計-超市收銀系統_第5頁
已閱讀5頁,還剩25頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、軟 件 學 院課程設計報告書 2011 年 6 月目錄1 設計時間32 設計目的33設計任務33.1任務說明33.2系統目標33.3使用范圍34 設計內容34.1界面構建34.2詳細設計34.2.1模塊設計44.2.2運行調試44.2.3部分源程序85 總結與展望28參考文獻29成績評定291 設計時間2011年6月11日-2011年6月15日2 設計目的通過實踐加深學生對面向對象程序設計的理論、方法和基礎知識的理解,掌握使用Java語言進行面向對象設計的基本方法,提高運用面向對象知識分析實際問題、解決實際問題的能力,提高學生的應用能力。3設計任務3.1任務說明設計出一個超市收銀程序(1)使用

2、圖形用戶界面實現。信息返回給收銀臺,計算出該顧客所購商品的總價格。(3)每天營業結束把該收銀臺的銷售總額進行統計匯總(要求包括商品種類、數量、銷售總額、結賬人次等信息,其余可自行豐富)并存儲在數據庫中。(4)所有持卡顧客的消費商品情況存儲到文件以供查詢。(5)對沒有卡的消費情況不記錄該顧客的消費情況等個人信息。如果一個未持卡顧客一次購物滿200元,結完賬后系統提示可為其發放一張會員卡3.2系統目標該軟件開發的用途是用來方便超市的收銀管理,提高辦事效率。3.3使用范圍本程序用于超市對會員和非會員的銷售管理4 設計內容 4.1界面構建為了便于各種操作,軟件采用多窗口的模式。用戶可在不同窗口進行相應

3、操作。4.2詳細設計4.2.1模塊設計 用戶登錄確認密碼操作界面輸入商品編號刪除商品修改數量修改價格完成結算會員結算否是銷售情況4.2.2運行調試圖1登錄界面圖2操作界面圖3.1修改數量圖3.2 填入要修改數量的商品號圖3.3輸入新數量圖4.1 普通結算圖4.2會員結算圖5銷售情況圖6系統時間4.2.3部分源程序登錄import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.FileReader;import java.io

4、.IOException;import java.util.StringTokenizer;import javax.swing.*;public class land public static void main(String args) landframe frame = new landframe();frame.setTitle(收營員登陸);frame.setLocation(300,300);frame.setSize(270, 170);frame.setVisible(true);class landframe extends JDialog implements Actio

5、nListener public landframe() label1 = new JLabel(JAVA超市收營系統 請登陸);label2 = new JLabel(用戶名:);label3 = new JLabel(密碼:);hbox1 = Box.createHorizontalBox();hbox2 = Box.createHorizontalBox();vbox = Box.createVerticalBox();jf1 = new JTextField();JPF= new JPasswordField();JPF.addActionListener(this);land = n

6、ew JButton(登陸);land.addActionListener(this);panel1 = new JPanel();panel2 = new JPanel();hbox1.add(label2);hbox1.add(Box.createHorizontalStrut(5);hbox1.add(jf1);hbox2.add(label3);hbox2.add(Box.createHorizontalStrut(18);panel2.add(land, Center);hbox2.add(JPF);vbox.add(label1);vbox.add(Box.createVertic

7、alStrut(10);vbox.add(hbox1);vbox.add(Box.createVerticalStrut(10);vbox.add(hbox2);vbox.add(Box.createVerticalStrut(10);vbox.add(panel2);panel1.add(vbox);getContentPane().add(panel1, Center);public void actionPerformed(ActionEvent evt) Object source = evt.getSource();if (source = land | source = JPF)

8、/ 登陸按紐及第二個文本輸入框ENTER功能實現String a = , b, read;boolean denglusuccees = false;try FileReader fr = new FileReader(denglu.txt);BufferedReader br = new BufferedReader(fr);while (read = br.readLine() != null) StringTokenizer sto = new StringTokenizer(read);a = sto.nextToken();b = sto.nextToken();if (jf1.ge

9、tText().equals(a) & JPF.getText().equals(b) denglusuccees = true;break;/ 驗證登陸員號碼及密碼 catch (IOException ie) System.err.println(ie.getMessage();if (denglusuccees = true) setVisible(false);mainview mw = new mainview();mw.setTitle(a + 為您服務);mw.setSize(850, 500);mw.setLocation(200, 180);mw.setVisible(tru

10、e); else jf1.setText();JPF.setText();JOptionPane.showMessageDialog(null, 非法用戶);private JLabel label1, label2, label3;private Box hbox1, hbox2, vbox;private JTextField jf1;private JPasswordField JPF;private JButton land;private JPanel panel1, panel2;物價計算public class draw double a;double b;String c;pu

11、blic draw(double fnum, double all, String information) / 構造函數a = fnum;/ 獲得指定商品當銷售額b = all;/ 獲得當天總銷售額c = information;/ 獲得指定商品的編號DrawJDialog frame = new DrawJDialog();frame.setSize(400, 300);frame.setLocation(400, 300);frame.setVisible(true);class DrawJDialog extends JDialog implements ActionListener/

12、 界面及功能實現JButton shut;JTextArea one = new JTextArea();DrawPanel panel = new DrawPanel();shut = new JButton(關閉);shut.addActionListener(this);double rate = 100 * a / b;DecimalFormat df = new DecimalFormat(#.00);rate = Double.parseDouble(df.format(rate);/ 格式化小數顯示one.setText( + c + n + 占今天銷售額 + rate + %)

13、;panel.add(one);panel.add(shut);Container contentPane = getContentPane();contentPane.add(panel);setTitle(銷售情況);public void actionPerformed(ActionEvent evt) Object source = evt.getSource();setVisible(false);class DrawPanel extends JPanel/ 畫餅圖public void paintComponent(Graphics g) g.clearRect(30, 40,

14、150, 150);double x1 = a;double x2 = b;int angle;super.paintComponent(g);angle = (int) (360 * x1 / x2);g.setColor(Color.blue);g.drawArc(30, 100, 150, 150, 0, angle);g.fillArc(30, 100, 150, 150, 0, angle);g.setColor(Color.GREEN);g.drawArc(30, 100, 150, 150, 0 + angle, 360 - angle);g.fillArc(30, 100, 1

15、50, 150, 0 + angle, 360 - angle);應用操作import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.*;class mainview extends JFrame implements ActionListenerDataManagement m

16、ydata = new DataManagement();sellcount mysell = new sellcount();judge myjudge = new judge();int dcount = 1;public mainview() changeButton1 = new JButton(修改價格);changeButton1.addActionListener(this);changeButton1.setEnabled(false);changeButton2 = new JButton(修改數量);changeButton2.addActionListener(this)

17、;changeButton2.setEnabled(false);deleteButton = new JButton(刪除商品);deleteButton.addActionListener(this);deleteButton.setEnabled(false);finishButton = new JButton(完成結算);finishButton.addActionListener(this);finishButton.setEnabled(false);cheapButton = new JButton(會員結算);cheapButton.addActionListener(thi

18、s);cheapButton.setEnabled(false);recordButton = new JButton(記錄清單);recordButton.addActionListener(this);recordButton.setEnabled(false);moneyButton = new JButton(找零計算);moneyButton.addActionListener(this);moneyButton.setEnabled(false);clearButton = new JButton(清除清單);clearButton.addActionListener(this);

19、textAll = new JTextField(0);textAll.setEditable(false);textAll.setBorder(BorderFactory.createEtchedBorder();textChange = new JTextArea(7, 0);textChange.setEditable(false);textChange.setBorder(BorderFactory.createEtchedBorder();hbox2 = Box.createHorizontalBox();vbox2 = Box.createVerticalBox();vbox2.a

20、dd(Box.createVerticalStrut(9);vbox2.add(changeButton1);vbox2.add(Box.createVerticalStrut(9);vbox2.add(changeButton2);vbox2.add(Box.createVerticalStrut(9);vbox2.add(deleteButton);vbox2.add(Box.createVerticalStrut(9);vbox2.add(finishButton);vbox2.add(Box.createVerticalStrut(9);vbox2.add(cheapButton);v

21、box2.add(Box.createVerticalStrut(9);vbox2.add(textAll);vbox2.add(moneyButton);vbox2.add(textChange);vbox2.setBorder(BorderFactory.createEtchedBorder();textArea = new JTextArea(24, 37);textArea.setMaximumSize(textArea.getPreferredSize();textArea.setEditable(false);scrollPane = new JScrollPane(textAre

22、a);textAdd = new JTextField(20);textAdd.addActionListener(this);vbox1 = Box.createVerticalBox();hbox1 = Box.createHorizontalBox();label1 = new JLabel(此處輸入商品編號 );label2 = new JLabel(商品信息顯示:);drawButton = new JButton(單天商品銷售情況);drawButton.addActionListener(this);vbox1.add(label1);vbox1.add(textAdd);hbo

23、x1.add(label2);hbox1.add(drawButton);vbox1.add(hbox1);vbox1.add(scrollPane);vbox1.setBorder(BorderFactory.createLoweredBevelBorder();vbox3 = Box.createVerticalBox();hbox3 = Box.createHorizontalBox();label3 = new JLabel(最終清單);label4 = new JLabel(版權所屬);label4.setBorder(BorderFactory.createEtchedBorder

24、();textFinish = new JTextArea(24, 30);textFinish.setEditable(false);textFinish.setBorder(BorderFactory.createEtchedBorder(Color.WHITE,Color.BLACK);hbox3.add(recordButton);hbox3.add(Box.createHorizontalStrut(10);hbox3.add(clearButton);hbox3.add(Box.createHorizontalStrut(10);hbox3.add(label4);vbox3.ad

25、d(new clock();vbox3.add(label3);hbox3.setBorder(BorderFactory.createEtchedBorder();vbox3.add(textFinish);vbox3.add(hbox3);vbox3.setBorder(BorderFactory.createLoweredBevelBorder();hbox2.add(vbox1);hbox2.add(vbox2);hbox2.add(vbox3);getContentPane().add(hbox2);addWindowListener(new WindowAdapter() publ

26、ic void windowClosing(WindowEvent e) System.exit(0););public void actionPerformed(ActionEvent evt) Object source = evt.getSource();if (source = textAdd) / 商品添加String log = textAdd.getText();StringTokenizer sto = new StringTokenizer(log);String dcode = sto.nextToken();boolean inputwrite = true;int dn

27、um = 1;if (sto.hasMoreTokens()try int tempnum=Integer.parseInt(sto.nextToken();if(tempnum0)dnum = Integer.parseInt(sto.nextToken();else inputwrite=false; catch (NumberFormatException e) JOptionPane.showMessageDialog(null, 請輸入數字);inputwrite = false;if (inputwrite = true) if (myjudge.find(dcode) = -1)

28、 String wrong = Cant find + dcode;JOptionPane.showMessageDialog(null, wrong);textAdd.setText(); else int location = myjudge.find(dcode);String dname = myjudge.judgeDatalocation.getName();double dprice = myjudge.judgeDatalocation.getPrice();mydata.add(dcode, dname, dprice, dnum);textArea.setText();fo

29、r (int i = 0; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode() + 商品名稱:+ ductDatai.getName() + 商品價格: + ductDatai.getPrice() + 元/單位 + ductDatai.getNum() + 個 + n,0);textArea.insert( 共 + mydata.givecost() + 元n, 0);textAdd.setText();chan

30、geButton1.setEnabled(true);changeButton2.setEnabled(true);deleteButton.setEnabled(true);cheapButton.setEnabled(true);finishButton.setEnabled(true); else textAdd.setText();else if (source = drawButton) String ecode = JOptionPane.showInputDialog(null, 請輸入欲查詢的商品編號);if (ecode != null) if (mysell.find(ec

31、ode) = -1)JOptionPane.showMessageDialog(null, 今天還未出售 + ecode);elsenew draw(mysell.sellDatamysell.find(ecode).getNum()* mysell.sellDatamysell.find(ecode).getPrice(),mysell.givecost(), mysell.sellinformantion(mysell.find(ecode);else if (source = changeButton1) double tempprice;String changepricecode =

32、 JOptionPane.showInputDialog(輸入要修改價格的商品編號);if (changepricecode != null) int getpchange = mydata.find(changepricecode);if (getpchange = -1)JOptionPane.showMessageDialog(null, 用戶未購買貨物+ changepricecode);else double price = ductDatagetpchange.getPrice();try tempprice = Double.parseDouble(JOpti

33、onPane.showInputDialog(輸入新單價);while (tempprice = 0) tempprice = Double.parseDouble(JOptionPane.showInputDialog(重新輸入新單價(系統默認大于零元));price=tempprice; catch (NumberFormatException e) JOptionPane.showMessageDialog(null, 請輸入數字);ductDatagetpchange.setPrice(price);textArea.setText();for (int i = 0

34、; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode() + 商品名稱:+ ductDatai.getName() + 商品價格: + ductDatai.getPrice() + 元/單位 + ductDatai.getNum() + 個 + n,0);textArea.insert( 共 + mydata.givecost() + 元n, 0);else if (source = changeButton2) S

35、tring changenum = JOptionPane.showInputDialog(輸入要修改數量的商品編號);if (changenum != null) int getnchange = mydata.find(changenum);if (getnchange = -1)JOptionPane.showMessageDialog(null, 用戶未購買貨物 + changenum);else int num = ductDatagetnchange.getNum();try num = Integer.parseInt(JOptionPane.showInpu

36、tDialog(輸入新數量);while (num =0)ductDatagetnchange.setNum(num);textArea.setText();for (int i = 0; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode() + 商品名稱:+ ductDatai.getName() + 商品價格: + ductDatai.getPrice() + 元/單位 + ductDatai

37、.getNum() + 個 + n,0);textArea.insert( 共 + mydata.givecost() + 元n, 0);else if (source = deleteButton) String deletecode = JOptionPane.showInputDialog(輸入所要刪除貨物的編號);if (deletecode != null) boolean getdelete = mydata.delete(deletecode);if (getdelete = false)JOptionPane.showMessageDialog(null, 用戶未購買貨物 +

38、deletecode);else textArea.setText();for (int i = 0; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode() + 商品名稱:+ ductDatai.getName() + 商品價格: + ductDatai.getPrice() + 元/單位 + ductDatai.getNum() + 個 + n,0);textArea.insert( 共 + mydata.give

39、cost() + 元n, 0);else if (source = finishButton) int a = JOptionPane.showConfirmDialog(null, 確定后將不可再修改清單);if (a = JOptionPane.YES_OPTION) textArea.setText();textFinish.insert( 謝謝您的惠顧, 0);textFinish.insert( 共 + mydata.givecost() + 元n, 0);textFinish.insert(-+ n, 0);for (int i = 0; i mydata.acount; i+)

40、textFinish.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode() + 商品名稱:+ ductDatai.getName() + 商品價格: + ductDatai.getPrice() + 元/單位 + ductDatai.getNum() + 個 + n, 0);textFinish.insert(-+ n, 0);textFinish.insert(軟院小超市 + n, 0);textAll.setText(總價: + mydata.givecost();mys

41、ell.save(mydata);changeButton1.setEnabled(false);changeButton2.setEnabled(false);deleteButton.setEnabled(false);recordButton.setEnabled(true);moneyButton.setEnabled(true);cheapButton.setEnabled(false);finishButton.setEnabled(false);textAdd.setEnabled(false);recordButton.doClick();else if (source = c

42、heapButton) String vipnumber = ;vipnumber = JOptionPane.showInputDialog(null, 請輸入VIP用戶會員號碼);if (vipnumber != null) boolean vipsuccees = false;String read;try FileReader fr = new FileReader(vip.txt);BufferedReader br = new BufferedReader(fr);while (read = br.readLine() != null) if (vipnumber.equals(r

43、ead) vipsuccees = true;break; catch (IOException ie) System.err.println(ie.getMessage();if (vipsuccees = true) int a = JOptionPane.showConfirmDialog(null, 確定后將不可再修改清單);if (a = JOptionPane.YES_OPTION) textArea.setText();textFinish.insert( VIP會員 + vipnumber + 優惠50%,只需 + mydata.givecost2() + 元, 0);text

44、Finish.insert( 原價 + mydata.givecost() + 元n, 0);textFinish.insert(-+ n, 0);for (int i = 0; i mydata.acount; i+) textFinish.insert(商品 + (i + 1) + 編號:+ ductDatai.getCode()+ 商品名稱:+ ductDatai.getName()+ 商品價格: + ductDatai.getPrice()+ 元/單位 + ductDatai.getNum()+ 個 + n

45、, 0);textFinish.insert(-+ n, 0);textFinish.insert(軟院小超市 + n, 0);textAll.setText(總價: + mydata.givecost2();mysell.save(mydata);changeButton1.setEnabled(false);changeButton2.setEnabled(false);deleteButton.setEnabled(false);recordButton.setEnabled(true);moneyButton.setEnabled(true);cheapButton.setEnable

46、d(false);finishButton.setEnabled(false);textAdd.setEnabled(false);recordButton.doClick(); elseJOptionPane.showMessageDialog(null, 非VIP會員號碼);else if (source = recordButton) mydata.record();JOptionPane.showMessageDialog(null, 交易信息記錄成功);recordButton.setEnabled(false);else if (source = moneyButton) String clientmoney = JOptionPane.showInputDialog(用戶給予金額);if (clientmoney != null) double inmoney = Double.parseDouble(clientmoney);String outmoney = mydata.moneycount(inmoney);textChange.setText(outmoney);moneyButton.setEnabled(false);else if

溫馨提示

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

評論

0/150

提交評論