JAVA课程设计超市收银系统

上传人:1777****777 文档编号:36982144 上传时间:2021-11-01 格式:DOC 页数:30 大小:204.02KB
返回 下载 相关 举报
JAVA课程设计超市收银系统_第1页
第1页 / 共30页
JAVA课程设计超市收银系统_第2页
第2页 / 共30页
JAVA课程设计超市收银系统_第3页
第3页 / 共30页
点击查看更多>>
资源描述
软 件 学 院课程设计报告书 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)使用图形用户界面实现。信息返回给收银台,计算出该顾客所购商品的总价格。(3)每天营业结束把该收银台的销售总额进行统计汇总(要求包括商品种类、数量、销售总额、结账人次等信息,其余可自行丰富)并存储在数据库中。(4)所有持卡顾客的消费商品情况存储到文件以供查询。(5)对没有卡的消费情况不记录该顾客的消费情况等个人信息。如果一个未持卡顾客一次购物满200元,结完账后系统提示可为其发放一张会员卡3.2系统目标该软件开发的用途是用来方便超市的收银管理,提高办事效率。3.3使用范围本程序用于超市对会员和非会员的销售管理4 设计内容 4.1界面构建为了便于各种操作,软件采用多窗口的模式。用户可在不同窗口进行相应操作。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.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 ActionListener 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 = new 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.createVerticalStrut(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) / 登陆按纽及第二个文本输入框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.getText().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(true); 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;public 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/ 界面及功能实现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 + %);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, 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, 150, 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 mydata = 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);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(this);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);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.add(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);vbox2.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(textArea);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);hbox1.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();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.add(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() public 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 dnum = 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) 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();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.givecost() + 元n, 0);textAdd.setText();changeButton1.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(ecode) = -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 = 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(JOptionPane.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; 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) String 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.showInputDialog(输入新数量);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.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, 用户未购买货物 + 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.givecost() + 元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() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai.getNum() + 个 + n, 0);textFinish.insert(-+ n, 0);textFinish.insert(软院小超市 + n, 0);textAll.setText(总价: + mydata.givecost();mysell.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 = cheapButton) 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(read) 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);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()+ 商品价格: + mydata.productDatai.getPrice()+ 元/单位 + mydata.productDatai.getNum()+ 个 + n, 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.setEnabled(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 (source = clearButton) textAdd.setText();textArea.setText();textAll.setText();textChange.setText();textFinish.setText();dcount = 0;mydata.clear();moneyButton.setEnabled(false);recordButton.setEnabled(false);changeButton1.setEnabled(false);changeButton2.setEnabled(false);deleteButton.setEnabled(false);cheapButton.setEnabled(false);finishButton.setEnabled(false);textAdd.setEnabled(true);private JButton changeButton1, changeButton2, deleteButton, finishButton,clearButton;private JButton recordButton, moneyButton, cheapButton, drawButton;private JLabel label1, label2, label3, label4;private JTextArea textArea, textChange, textFinish;private JScrollPane scrollPane;private JTextField textAdd, textAll;private Box vbox1, vbox2, vbox3, hbox1, hbox2, hbox3;5 总结与展望第一次接触JAVA这个东西真的让人感觉到有许多的陌生感,虽然一开始觉得和C语言很像,但学着学着就发现它与C语言还是有许多不同的地方,不能千篇一律的照搬C语言。学了这么久JAVA,课程设计是最能展示出学习成果的。在这次设计中,一次次的失败让我感到十分的无力,但是我还是坚持做了下来,尽管仍然不完美,但是我想我尽力了!这次设计让人遗憾的是最后的让非会员自动转为会员的一步我没有能够做出来。在这次课程设计中,我对JAVA的跨平台性有了更进一步的认识。为了能够准确地设计出程序,我多次核对课本上的知识,对程序进行了很大的改进。当遇到自己不能解决的问题时,也上网查询的许多的信息,同时也向其他同学进行了的咨询。终于完成了现在的课程设计!在这次设计中,遇到的了许多问题。如:从最简单的主窗体,到主窗体的菜单,组件添加,再到各个功能的独立窗体的建立,功能的实现,一步步走来,收获颇多。其中独立窗体中的组件排版是碰到的第一个问题,最简单的方法是在建每个窗体时把所有需要的组件全部重新添加进去,但是这样代码会很长,而却会多占很多内存空间,于是我决定把个功能窗体中共同的组件在一个新方法中统一加载,为了减小占内存空间,组建的在主类的构造方法中生成,所有独立功能窗口公用组件,这样既减少了代码额长度,又提高了程序的内存利用率。还有很多问题,都在权衡之后得到了较优的解决方法。我希望在未来的JAVA道路上能够走的更远!参考文献1 屈辉立,陈可明,石武信.JSP网站编程教程M.第1版, 北京:北京希望电子出版社,2005 2 白勇.用B/S模式构建在线考试系统J,重庆电力高等专科学校学报,2003,10(4): 100130. 3李钟尉,马文强,陈丹丹Java从入门到精通 第1版 清华大学出版社 2008.94刘万军,梁清华,王松波,宋强Java程序设计实践教程 第1版 清华大学出版社2006.9 成绩评定
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸设计 > 任务书类


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!