JAVA课程设计-超市收银系统.doc

上传人:来看看 文档编号:3258275 上传时间:2019-08-06 格式:DOC 页数:30 大小:204.03KB
返回 下载 相关 举报
JAVA课程设计-超市收银系统.doc_第1页
第1页 / 共30页
JAVA课程设计-超市收银系统.doc_第2页
第2页 / 共30页
JAVA课程设计-超市收银系统.doc_第3页
第3页 / 共30页
JAVA课程设计-超市收银系统.doc_第4页
第4页 / 共30页
JAVA课程设计-超市收银系统.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《JAVA课程设计-超市收银系统.doc》由会员分享,可在线阅读,更多相关《JAVA课程设计-超市收银系统.doc(30页珍藏版)》请在三一文库上搜索。

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) + 编号:+ mydata.productDatai.getCode() + 商品名称:+ mydata.productDatai.getName() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai.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 = mydata.productDatagetpchange.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, 请输入数字);mydata.productDatagetpchange.setPrice(price);textArea.setText();for (int i = 0

34、; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 编号:+ mydata.productDatai.getCode() + 商品名称:+ mydata.productDatai.getName() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai.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 = mydata.productDatagetnchange.getNum();try num = Integer.parseInt(JOptionPane.showInpu

36、tDialog(输入新数量);while (num =0)mydata.productDatagetnchange.setNum(num);textArea.setText();for (int i = 0; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 编号:+ mydata.productDatai.getCode() + 商品名称:+ mydata.productDatai.getName() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai

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) + 编号:+ mydata.productDatai.getCode() + 商品名称:+ mydata.productDatai.getName() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai.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+) textFinish.insert(商品 + (i + 1) + 编号:+ mydata.productDatai.getCode() + 商品名称:+ mydata.productDatai.getName()

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 研究报告 > 信息产业


经营许可证编号:宁ICP备18001539号-1