1、基于socket网络编程的超市收银管理系统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 nam
2、e, String unit, int amount, double price, double money) this.name = name; this.unit = unit; this.amount = amount; this.price = price; this.money = money; public String getName() return name; public void setName(String name) this.name = name; public String getUnit() return unit; public void setUnit(S
3、tring 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.mon
4、ey = 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() r
5、eturn 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 un
6、it; 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; th
7、is.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 user
8、name) 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;/* * 会员类 * */Su
9、ppressWarnings(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 getS
10、core() 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;impor
11、t 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) thro
12、ws Exception, Exception / 发送方法 Socket s = new Socket(127.0.0.1, 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();
13、 / 关闭流 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 (choo
14、se = 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();
15、 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; whi
16、le (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:/ 退出
17、 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);
18、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_
19、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:新增商品!); Suppres
20、sWarnings(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)
21、= 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
22、 + 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()
23、+ 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 Ha
24、shMap(); 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(输入商
25、品数量:); 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.getA
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1