java基于socket网络编程的超市收银管理系统.doc_第1页
java基于socket网络编程的超市收银管理系统.doc_第2页
java基于socket网络编程的超市收银管理系统.doc_第3页
java基于socket网络编程的超市收银管理系统.doc_第4页
java基于socket网络编程的超市收银管理系统.doc_第5页
已阅读5页,还剩116页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

package entity;import java.io.Serializable;/* * 收银类 * */SuppressWarnings(serial)public class Cash implements Serializable private String name;/ 商品名private String unit;/ 商品单位private int amount;/ 商品数量private double price;/ 商品单价private double money;/ 商品金额public Cash(String name, String unit, int amount, double price, double money) = name;this.unit = unit;this.amount = amount;this.price = price;this.money = money;public String getName() return name;public void setName(String name) = name;public String getUnit() return unit;public void setUnit(String unit) this.unit = unit;public int getAmount() return amount;public void setAmount(int amount) this.amount = amount;public double getPrice() return price;public void setPrice(double price) this.price = price;public double getMoney() return money;public void setMoney(double money) this.money = money;package entity;import java.io.Serializable;/* * 商品类 * */SuppressWarnings(serial)public class ShangPin implements Serializable private String number;/ 商品编号private String spname;/ 商品名称private double price;/ 商品单价private String unit;/ 单位private int amount;/ 数量public String getNumber() return number;public void setNumber(String number) this.number = number;public String getSpname() return spname;public void setSpname(String spname) this.spname = spname;public double getPrice() return price;public void setPrice(double price) this.price = price;public String getUnit() return unit;public void setUnit(String unit) this.unit = unit;public int getAmount() return amount;public void setAmount(int amount) this.amount = amount;public ShangPin(String number, String spname, double price, String unit,int amount) this.number = number;this.spname = spname;this.price = price;this.unit = unit;this.amount = amount;package entity;/* * 用户类 */import java.io.Serializable;SuppressWarnings(serial)public class User implements Serializable private String username;/ 用户名称private String password;/ 用户密码public String getUsername() return username;public void setUsername(String username) this.username = username;public String getPassword() return password;public void setPassword(String password) this.password = password;public User(String username, String password) this.username = username;this.password = password;package entity;import java.io.Serializable;/* * 会员类 * */SuppressWarnings(serial)public class Vip implements Serializable private String vipId;/ 会员卡号private int score;/ 会员积分public Vip(String vipId,int score)this.vipId = vipId;this.score = score;public String getVipId() return vipId;public void setVipId(String vipId) this.vipId = vipId;public int getScore() return score;public void setScore(int score) this.score = score;package socket;/* * 客户端类 * */import java.io.InputStream;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.OutputStream;import .Socket;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Map;import java.util.Scanner;import entity.Cash;import entity.ShangPin;public class Client static Scanner input = new Scanner(System.in);private static Object receive;private static String username;static int count = 0;private static Object send(Map map) throws Exception,Exception / 发送方法Socket s = new Socket(, 8800);OutputStream os = s.getOutputStream();ObjectOutputStream oos = new ObjectOutputStream(os);oos.writeObject(map);InputStream is = s.getInputStream();ObjectInputStream ois = new ObjectInputStream(is);receive = ois.readObject();/ 关闭流oos.close();os.close();is.close();ois.close();return receive;public static void main(String args) throws Exception System.out.println(*欢迎使用青鸟超市管理系统*);System.out.println(1.登陆);System.out.println(2.退出系统);System.out.println(*请选择数字1/2*);while (true) int choose = input.nextInt();if (choose = 1) do System.out.print(用户名称:);username = input.next();System.out.print(用户密码:);String password = input.next();Map map = new HashMap();map.put(账号, username);map.put(密码, password);map.put(send, 登录);send(map);/ 库存管理员界面if (管理员.equals(receive) System.out.println(*欢迎登录青鸟超市库存管理系统*);admin(); else if (收银员.equals(receive) System.out.println(*欢迎登录青鸟超市收银系统*);cash(); else System.out.println(用户名或者密码输入错误!登录失败!); while (true); else if (choose = 2) System.out.println(您已经退出系统!);break; else System.out.println(输入错误!请重新选择数字1/2:);private static void admin() throws Exception / 管理员int choose;while (true) System.out.println(请选择进行的操作:1.商品入库 t 2.商品出库 t 3.新增商品 t 4.查询所有商品 t 5.按编号查询商品 t 6.退出);choose = input.nextInt();/ 选择库存操作switch (choose) case 1:/ 入库in();break;case 2:/ 出库out();break;case 3:/ 新增add();break;case 4:/ 打印所有商品checkall();break;case 5:/ 按编号查询check();break;case 6:/ 退出System.out.println(谢谢使用!);break;default:System.out.println(对不起,您的输入有误,请重新输入!);break;SuppressWarnings(unchecked)private static void in() throws Exception / 入库System.out.print(输入商品编号:);String number = input.next();Map map = new HashMap();map.put(编号, number);map.put(send, 查询编号);send(map);if (有此商品.equals(receive) System.out.print(入库数量:);String amount = input.next();if (num(amount) = true) int a = Integer.parseInt(amount);if (a = 0) map.put(入库数量, amount);map.put(send, 入库);Map map1 = (Map) send(map);System.out.println(商品编号tt + 商品名称tt + 商品单价tt+ 单位tt + 数量);for (ShangPin iterable_element : map1.values() System.out.println(iterable_element.getNumber()+ tt + iterable_element.getSpname()+ tt + iterable_element.getPrice() + tt+ iterable_element.getUnit() + tt+ iterable_element.getAmount(); else System.out.println(出库数量有误!); else System.out.println(没有此商品,请选择编号3:新增商品!);SuppressWarnings(unchecked)private static void out() throws Exception / 出库System.out.print(输入商品编号:);String number = input.next();Map map = new HashMap();map.put(编号, number);map.put(send, 查询编号);send(map);if (有此商品.equals(receive) System.out.print(出库数量:);String amount = input.next();if (num(amount) = true) int a = Integer.parseInt(amount);if (a = 0) map.put(出库数量, amount);map.put(send, 出库);send(map);Map map1 = (Map) receive;if (a = map1.get(number).getAmount() System.out.println(商品编号tt + 商品名称tt+ 商品单价ttt + 单位ttt + 数量);for (ShangPin sp : map1.values() System.out.println(sp.getNumber() + tt+ sp.getSpname() + tt + sp.getPrice()+ tt + sp.getUnit() + tt+ sp.getAmount(); else System.out.println(库存不足,请核实,出库失败!);System.out.println(商品编号tt + 商品名称tt + 商品单价tt+ 单位tt + 数量);System.out.println(map1.get(number).getNumber()+ tt + map1.get(number).getSpname()+ tt + map1.get(number).getPrice() + tt+ map1.get(number).getUnit() + tt+ map1.get(number).getAmount(); else System.out.println(出库数量有误!); else System.out.println(没有此商品!);SuppressWarnings(unchecked)private static void add() throws Exception / 新增while (true) System.out.print(输入商品编号:);String number = input.next();Map map = new HashMap();map.put(编号, number);map.put(send, 查询编号);send(map);if (无此商品.equals(receive) System.out.print(输入商品名称:);String spname = input.next();System.out.print(输入商品价格:);String price = input.next();if (price(price) = true) System.out.print(输入商品单位:);String unit = input.next();System.out.print(输入商品数量:);String amount = input.next();if (num(amount) = true) map.put(send, 新增);map.put(名称, spname);map.put(价格, price);map.put(单位, unit);map.put(数量, amount);send(map);System.out.println(新增商品成功!);Map map2 = (Map) receive;System.out.println(商品编号tt + 商品名称tt+ 商品单价ttt + 单位ttt + 数量);for (ShangPin sp : map2.values() System.out.println(sp.getNumber() + tt+ sp.getSpname() + tt + sp.getPrice()+ tt + sp.getUnit() + tt+ sp.getAmount();break; else System.out.println(此编号已存在);continue;SuppressWarnings(unchecked)private static void checkall() throws Exception / 查询全部Map map = new HashMap();map.put(send, 查询全部);send(map);Map map1 = (Map) receive;System.out.println(商品编号tt + 商品名称tt + 商品单价tt + 单位tt+ 数量);for (ShangPin sp : map1.values() System.out.println(sp.getNumber() + tt + sp.getSpname()+ tt + sp.getPrice() + tt + sp.getUnit() + tt+ sp.getAmount();SuppressWarnings(unchecked)private static void check() throws Exception / 查询号查询System.out.print(输入商品编号:);String number = input.next();Map map = new HashMap();map.put(编号, number);map.put(send, 查询编号);send(map);if (有此商品.equals(receive) map.put(send, 查询号查询);send(map);Map map1 = (Map) receive;System.out.println(商品编号tt + 商品名称tt + 商品单价ttt+ 单位ttt + 数量);for (ShangPin sp : map1.values() System.out.println(sp.getNumber() + tt + sp.getSpname()+ tt + sp.getPrice() + tt + sp.getUnit()+ tt + sp.getAmount(); else System.out.println(对不起,没有此商品!);private static void cash() throws Exception / 收银int choose;while (true) System.out.println(请选择进行的操作:1.扫描商品 t 2.修改数量 t 3.结账 t 4.退出);choose = input.nextInt();/ 选择库存操作switch (choose) case 1:/ 扫描scan();break;case 2:/ 修改数量modify();break;case 3:/ 新增checkout();break;case 4:/ 退出System.out.println(谢谢使用!);break;default:System.out.println(对不起,您的输入有误,请重新输入!);break;SuppressWarnings(unchecked)public static void scan() throws Exception / 扫描商品System.out.print(输入需要扫描的商品编号:);String number = input.next();Map map = new HashMap();map.put(编号, number);map.put(send, 查询编号);send(map);if (有此商品.equals(receive) System.out.println(扫描成功!);count+;String c = String.valueOf(count);map.put(send, 扫描);map.put(扫描次数, c);send(map);Map map2 = (Map) receive;System.out.println(商品名称tttt + 数量tt + 单价tt + 金额);System.out.println(-);for (Cash cash : map2.values() System.out.println(cash.getName() + cash.getUnit() + tt+ cash.getAmount() + tt + cash.getPrice() + tt+ cash.getMoney();System.out.println(-); else System.out.println(对不起,没有此商品,扫描失败);SuppressWarnings(unchecked)public static void modify() throws Exception / 修改购买数量Map map = new HashMap();if (count != 0) while (true) System.out.print(输入需要修改的商品编号:);String number = input.next();map.put(编号, number);map.put(send, 查询编号);send(map);if (有此商品.equals(receive) map.put(编号, number);map.put(send, 检测是否扫描);send(map);if (已被扫描.equals(receive) System.out.print(输入修改数量:);String amount = input.next();if (num(amount) = true) int a = Integer.parseInt(amount);if (a = 0) map.put(数量, amount);map.put(send, 修改数量);send(map);Map map2 = (Map) receive;System.out.println(商品名称tttt + 数量tt+ 单价tt + 金额);System.out.println(-);for (Cash cash : map2.values() System.out.println(cash.getName()+ cash.getUnit() + tt+ cash.getAmount() + tt+ cash.getPrice() + tt+ cash.getMoney();System.out.println(-); else System.out.println(修改数量有误!);break;break; else System.out.println(没有扫描此商品。);continue; else System.out.println(对不起,没有此商品,扫描失败!);break; else System.out.println(您还没有扫描商品!);SuppressWarnings(unchecked)public static void checkout() throws Exception / 结账double money = 0;Map map = new HashMap();if (count != 0) map.put(send, 结账);send(map);Map map1 = (Map) receive;for (Cash cash : map1.values() money += cash.getMoney();System.out.println(总金额是: + money);System.out.println(1.普通结账t2.会员结账);int i = input.nextInt();switch (i) case 1:/ 普通结账System.out.print(请输入您要支付的金额:);while (true) String money1 = input.next();if (money(money1) = true) double m = Double.parseDouble(money1); if (m = money) System.out.println(ttt青鸟超市);System.out.print(收银员号: + username + tt);Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddmmss);System.out.println(小票号: + sdf.format(date);System.out.println(序tt + 商品名称tttt+ 数量tt + 单价tt + 金额);int n = 1;/ 序号int a = 0;/ 总数量Map map2 = (Map) receive;System.out.println(-);for (Cash cash : map2.values() System.out.println(n + tt + cash.getName()+ cash.getUnit() + tt+ cash.getAmount() + tt+ cash.getPrice() + tt+ cash.getMoney();n+;a += cash.getAmount();System.out.println(-);System.out.println(总数量: + a + t应收: + money);System.out.println(实收: + m + t找零:+ (m - money);SimpleDateFormat sdf1 = new SimpleDateFormat(yyyy/MM/dd HH:mm:ss);System.out.println(sdf1.format(date);System.out.println(此小票是您退换货及核对积分的凭证,请妥善保存!);System.out.println(=);map.put(send, 普通);send(map);break; else System.out.println(请输入正确的金额!);break;case 2:/ 会员结账while (true) System.out.print(请输入您的会员卡号:);String vipid = input.next();map.put(send, 会员登录);map.put(会员账号, vipid);send(map);if (会员存在.equals(receive) System.out.print(会员卡号正确,请输入您要支付的金额:);String money1 = input.next();if (money(money1) = true)

温馨提示

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

评论

0/150

提交评论