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 impl

5、ements 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 jpass

6、wordfield();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, "

7、;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

8、(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()

9、 != 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(fals

10、e);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,

11、 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;/ 获得指定商品的编号drawjdia

12、log 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.addactio

13、nlistener(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 = getcon

14、tentpane();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;su

15、per.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.a

16、wt.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 = ne

17、w 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(

18、false);deletebutton = new jbutton("删除商品");deletebutton.addactionlistener(this);deletebutton.setenabled(false);finishbutton = new jbutton("完成结算");finishbutton.addactionlistener(this);finishbutton.setenabled(false);cheapbutton = new jbutton("会员结算");cheapbutton.addactionli

19、stener(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("清除

20、清单");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.createhorizonta

21、lbox();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.c

22、reateverticalstrut(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.seteditab

23、le(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("单天商品销售情况&

24、quot;);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

25、("最终清单");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.createhor

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

27、);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();stri

28、ngtokenizer 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(tempnum>0)dnum = integer.parseint(sto.nexttoken();else inputwrite=false; catch (numberformatexception e) jopt

29、ionpane.showmessagedialog(null, "请输入数字");inputwrite = false;if (inputwrite = true) if (myjudge.find(dcode) = -1) string wrong = "can't find " + dcode;joptionpane.showmessagedialog(null, wrong);textadd.settext(""); else int location = myjudge.find(dcode);string dname

30、 = 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) + " 编号:"+ ductdatai.getcode() + &qu

31、ot; 商品名称:"+ ductdatai.getname() + " 商品价格: "+ ductdatai.getprice() + "元/单位 "+ ductdatai.getnum() + " 个" + "n",0);textarea.insert(" 共" + mydata.givecost() + " 元n", 0);textadd.settext("");changebutt

32、on1.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)

33、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 temp

34、price;string changepricecode = joptionpane.showinputdialog("输入要修改价格的商品编号");if (changepricecode != null) int getpchange = mydata.find(changepricecode);if (getpchange = -1)joptionpane.showmessagedialog(null, "用户未购买货物"+ changepricecode);else double price = ductdatagetpchan

35、ge.getprice();try tempprice = double.parsedouble(joptionpane.showinputdialog("输入新单价");while (tempprice <= 0) tempprice = double.parsedouble(joptionpane.showinputdialog("重新输入新单价(系统默认大于零元)");price=tempprice; catch (numberformatexception e) joptionpane.showmessagedialog(null, &qu

36、ot;请输入数字");ductdatagetpchange.setprice(price);textarea.settext("");for (int i = 0; i < mydata.acount; i+) textarea.insert("商品" + (i + 1) + " 编号:"+ ductdatai.getcode() + " 商品名称:"+ ductdatai.getname() + " 商品价格: "+

37、ductdatai.getprice() + "元/单位 "+ ductdatai.getnum() + " 个" + "n",0);textarea.insert(" 共" + mydata.givecost() + " 元n", 0);else if (source = changebutton2) string changenum = joptionpane.showinputdialog("输入要修改数量的商品编号");if (

38、changenum != null) int getnchange = mydata.find(changenum);if (getnchange = -1)joptionpane.showmessagedialog(null, "用户未购买货物" + changenum);else int num = ductdatagetnchange.getnum();try num = integer.parseint(joptionpane.showinputdialog("输入新数量");while (num < 0) num =

39、integer.parseint(joptionpane.showinputdialog("重新输入新数量(系统默认大于等于零元)"); catch (numberformatexception e) joptionpane.showmessagedialog(null, "请输入数字");if (num = 0)mydata.delete(changenum);else if(num>=0)ductdatagetnchange.setnum(num);textarea.settext("");for (in

40、t i = 0; i < mydata.acount; i+) textarea.insert("商品" + (i + 1) + " 编号:"+ ductdatai.getcode() + " 商品名称:"+ ductdatai.getname() + " 商品价格: "+ ductdatai.getprice() + "元/单位 "+ ductdatai.getnum() + " 个" +

41、 "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.

42、showmessagedialog(null, "用户未购买货物" + deletecode);else textarea.settext("");for (int i = 0; i < mydata.acount; i+) textarea.insert("商品" + (i + 1) + " 编号:"+ ductdatai.getcode() + " 商品名称:"+ ductdatai.getname() + " 商品价格: "

43、+ ductdatai.getprice() + "元/单位 "+ ductdatai.getnum() + " 个" + "n",0);textarea.insert(" 共" + mydata.givecost() + " 元n", 0);else if (source = finishbutton) int a = joptionpane.showconfirmdialog(null, "确定后将不可再修改清单");if (a =

44、 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("商品" +

45、 (i + 1) + " 编号:"+ ductdatai.getcode() + " 商品名称:"+ ductdatai.getname() + " 商品价格: "+ ductdatai.getprice() + "元/单位 "+ ductdatai.getnum() + " 个" + "n", 0);textfinish.insert("-"+ "n",

46、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.set

47、enabled(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 filer

48、eader 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(nu

49、ll, "确定后将不可再修改清单");if (a = joptionpane.yes_option) textarea.settext("");textfinish.insert(" vip会员" + vipnumber + "优惠50%,只需 "+ mydata.givecost2() + "元", 0);textfinish.insert(" 原价" + mydata.givecost() + " 元n", 0);textfinish.insert(&

50、quot;-"+ "n", 0);for (int i = 0; i < mydata.acount; i+) textfinish.insert("商品" + (i + 1) + " 编号:"+ ductdatai.getcode()+ " 商品名称:"+ ductdatai.getname()+ " 商品价格: "+ ductdatai.getprice()+ "元/单位 " + mydata.p

51、roductdatai.getnum()+ " 个" + "n", 0);textfinish.insert("-"+ "n", 0);textfinish.insert("软院小超市" + "n", 0);textall.settext("总价:" + mydata.givecost2();mysell.save(mydata);changebutton1.setenabled(false);changebutton2.setenabled(false)

52、;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 = do

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论