Java语言开发超市销售管理系统

用Java语言完成程序开发,完成的系统应满足以下要求:
货物库存信息(商品编号,商品名称,商品分类,商品单价,库存量)、货物销售信息(订单编号,会员编号,商品编号,商品名称,商品分类,商品单价,销售时间)、工作人员信息(员工编号,员工姓名,员工密码,联系电话)存放在文本文件中,需要时从文件中读取。注:客户身份不需要登录系统,可以直接购物,如果是会员,则结账时记录会员信息,非会员则用同一个编号(编号自拟)。
1、基本功能要求:
1)提供给超市人员的基本功能:显示所有库存商品、添加商品、修改商品、删除商品。
2)提供给客户的基本功能:显示所有库存商品、添加商品到购物车、从购物车删除商品、结账、退出系统。
l显示所有库存商品:从文档中读取数据然后在控制台中显示;
l添加商品:可添加已有商品,添加成功则只需修改数据中的库存值即可,添加新商品则需要在文档中添加一条新记录;
l修改商品:可根据编号修改商品的其他属性信息,如果编号不对,则删除该条记录,重新添加,不可直接修改编号;
l删除商品:可以根据商品编号删除库存记录;
l添加商品到购物车:实现客户往购物车添加商品的功能;
l从购物车删除商品:客户可以从购物车中删除不需要的商品,根据商品编号删除;
l结账:显示购物车中的商品信息列表,并计算购物车中商品的总金额,完成结账后需要修改相应的库存量,还要把销售的商品记录到货物销售信息文档中,清空购物车。
l退出系统:结束程序。
2、中级功能要求:
商品查找功能:该功能超市人员和客户都可用,可以根据商品编号、名称、分类这些属性进行单条件或多条件查询。
3、高级功能要求:
1)实现客户退换货功能:根据订单编号实现商品的退或换的功能,需要相应地修改货物库存信息文档和货物销售信息文档。
2)可以按照商品销售额排序;

参考 https://blog.csdn.net/qq_45241180/article/details/119106392

是要图形界面程序吗还说是控制台输出那种

推荐一个开源项目
https://github.com/five517/SMBMS

你是要自己开发,需要给你推荐项目,还是?

需要前端页面吗?

Java语言开发超市销售管理系统

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
 
public class MainFrame extends JFrame{
    private static final long serialVersionUID = -8808883923263763897L;
    
    private ClientContext clientContext;
    
    public MainFrame(){
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        init();
    }
    
    public void init(){
        this.setTitle("小型商店进销存管理系统");
        this.setSize(550, 400);
        this.setContentPane(createContentPane());
        int windowWidth = this.getWidth(); //获得窗口宽
        int windowHeight = this.getHeight(); //获得窗口高
        Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包
        Dimension screenSize = kit.getScreenSize(); //获取屏幕的尺寸
        int screenWidth = screenSize.width; //获取屏幕的宽
        int screenHeight = screenSize.height; //获取屏幕的高
        this.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);//设置窗口居中显示
        this.setResizable(false);
    }
 
    private Container createContentPane() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(createFunctionPanel(), BorderLayout.CENTER);
        return panel;
    }
 
    private Component createFunctionPanel() {
        Image image=new ImageIcon(MainFrame.class.getResource("icon/bg.png")).getImage(); 
        JPanel panel = new BackgroundPanel(image);
        Font font16=new Font("微软雅黑", 1, 16);
        
        JButton sale=new JButton("销  售",new ImageIcon(MainFrame.class.getResource("icon/sell.png")));
        sale.setHorizontalTextPosition(SwingConstants.CENTER);
        sale.setVerticalTextPosition(SwingConstants.BOTTOM);
        sale.setBorderPainted(false);
        sale.setFocusPainted(false);
        sale.setContentAreaFilled(false);
        sale.setFocusable(true);
        sale.setMargin(new Insets(180, 10, 0, 30));
        sale.setFont(font16);
        sale.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                clientContext.showSellFrame();
            }
        });
        panel.add(sale);
        
        JButton purchases=new JButton("进  货",new ImageIcon(MainFrame.class.getResource("icon/inventory.png")));
        purchases.setHorizontalTextPosition(SwingConstants.CENTER);
        purchases.setVerticalTextPosition(SwingConstants.BOTTOM);
        purchases.setBorderPainted(false);
        purchases.setFocusPainted(false);
        purchases.setContentAreaFilled(false);
        purchases.setFocusable(true);
        purchases.setMargin(new Insets(180, 10, 0, 30));
        purchases.setFont(font16);
        purchases.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                clientContext.showOrHidePurchaseFrame(true);
            }
        });
        panel.add(purchases);
        
        JButton stock=new JButton("库  存",new ImageIcon(MainFrame.class.getResource("icon/storage.png")));
        stock.setHorizontalTextPosition(SwingConstants.CENTER);
        stock.setVerticalTextPosition(SwingConstants.BOTTOM);
        stock.setBorderPainted(false);
        stock.setFocusPainted(false);
        stock.setContentAreaFilled(false);
        stock.setFocusable(true);
        stock.setMargin(new Insets(180, 10, 0, 30));
        stock.setFont(font16);
        stock.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                clientContext.showOrHideStorageFrame(true);
            }
        });
        panel.add(stock);
        
        JButton sellHistoryBtn=new JButton("销售记录",new ImageIcon(MainFrame.class.getResource("icon/summary.png")));
        sellHistoryBtn.setHorizontalTextPosition(SwingConstants.CENTER);
        sellHistoryBtn.setVerticalTextPosition(SwingConstants.BOTTOM);
        sellHistoryBtn.setBorderPainted(false);
        sellHistoryBtn.setFocusPainted(false);
        sellHistoryBtn.setContentAreaFilled(false);
        sellHistoryBtn.setFocusable(true);
        sellHistoryBtn.setMargin(new Insets(180, 10, 0, 10));
        sellHistoryBtn.setFont(font16);
        sellHistoryBtn.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                clientContext.showSellHistoryFrame();
            }
        });
        panel.add(sellHistoryBtn);
        
        JButton setting=new JButton("修改密码",new ImageIcon(MainFrame.class.getResource("icon/setting.png")));
        setting.setHorizontalTextPosition(SwingConstants.CENTER);
        setting.setVerticalTextPosition(SwingConstants.BOTTOM);
        setting.setBorderPainted(false);
        setting.setFocusPainted(false);
        setting.setContentAreaFilled(false);
        setting.setFocusable(true);
        setting.setMargin(new Insets(180, 10, 0, 10));
        setting.setFont(font16);
        setting.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                clientContext.showModifyPwdFrame(true);
            }
        });
        panel.add(setting);
        
        return panel;
    }
 
    public static void main(String[] args) {
        MainFrame mf = new MainFrame();
        mf.init();
        mf.setVisible(true);
    }
 
    public ClientContext getClientContext() {
        return clientContext;
    }
 
    public void setClientContext(ClientContext clientContext) {
        this.clientContext = clientContext;
    }
 
}

以下是用Java语言实现上述系统的基本代码框架,其中包含了所需的基本功能。请注意,这只是一个初始的代码框架,你可以根据需要进行进一步的开发和完善。

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class SupermarketSystem {
    private List<Product> inventory;
    private List<Product> shoppingCart;

    public SupermarketSystem() {
        inventory = new ArrayList<>();
        shoppingCart = new ArrayList<>();
    }

    public void start() {
        loadInventoryFromFile(); // 从文件中加载库存信息
        showInventory(); // 显示所有库存商品

        boolean quit = false;
        do {
            int choice = displayMenu(); // 显示主菜单选项
            switch(choice) {
                case 1:
                    addProductToCart(); // 添加商品到购物车
                    break;
                case 2:
                    removeProductFromCart(); // 从购物车删除商品
                    break;
                case 3:
                    checkout(); // 结账
                    break;
                case 4:
                    quit = true; // 退出系统
                    break;
                default:
                    System.out.println("无效的选项,请重新输入!");
                    break;
            }
        } while(!quit);
    }

    public void showInventory() {
        for (Product product : inventory) {
            System.out.println(product);
        }
    }

    public void addProductToCart() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要添加到购物车的商品编号:");
        String productId = scanner.nextLine();
        
        boolean found = false;
        for (Product product : inventory) {
            if (product.getId().equals(productId)) {
                shoppingCart.add(product);
                found = true;
                break;
            }
        }
        
        if (found) {
            System.out.println("已将商品添加到购物车!");
        } else {
            System.out.println("找不到该商品!");
        }
    }

    public void removeProductFromCart() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要从购物车中删除的商品编号:");
        String productId = scanner.nextLine();

        boolean found = false;
        for (Product product : shoppingCart) {
            if (product.getId().equals(productId)) {
                shoppingCart.remove(product);
                found = true;
                break;
            }
        }

        if (found) {
            System.out.println("已从购物车中删除商品!");
        } else {
            System.out.println("找不到该商品!");
        }
    }

    public void checkout() {
        double totalAmount = 0;
        for (Product product : shoppingCart) {
            totalAmount += product.getPrice();
        }

        System.out.println("购物车中的商品信息:");
        for (Product product : shoppingCart) {
            System.out.println(product);
        }
        System.out.println("总金额: " + totalAmount);

        // 更新库存量
        for (Product product : shoppingCart) {
            for (Product inventoryProduct : inventory) {
                if (product.getId().equals(inventoryProduct.getId())) {
                    inventoryProduct.decreaseStock();
                    break;
                }
            }
        }

        // 记录销售信息到文件中(未实现)
        
        shoppingCart.clear();
        System.out.println("结账完成!");
    }

    public void loadInventoryFromFile() {
        // 从文本文件中读取库存信息并初始化inventory列表(未实现)
    }

    public int displayMenu() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("--- 超市系统菜单 ---");
        System.out.println("1. 添加商品到购物车");
        System.out.println("2. 从购物车删除商品");
        System.out.println("3. 结账");
        System.out.println("4. 退出系统");
        System.out.println("请选择:");
        int choice = scanner.nextInt();
        scanner.nextLine(); // 清空输入缓冲区
        return choice;
    }
  
    public static void main(String[] args) {
        SupermarketSystem supermarket = new SupermarketSystem();
        supermarket.start();
    }
}

class Product {
    private String id;
    private String name;
    private String category;
    private double price;
    private int stock;

    public Product(String id, String name, String category, double price, int stock) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.price = price;
        this.stock = stock;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getCategory() {
        return category;
    }

    public double getPrice() {
        return price;
    }

    public int getStock() {
        return stock;
    }

    public void decreaseStock() {
        stock--;
    }

    @Override
    public String toString() {
        return "商品编号:" + id + "\n商品名称:" + name + "\n商品分类:" + category +
                "\n商品单价:" + price + "\n库存量:" + stock + "\n";
    }
}

请注意,上述代码仅实现了基本功能的框架,仍需根据具体需求进行进一步开发和完善,例如文件读写操作、商品查找功能和高级功能的实现。

回答:可以参考这个超市销售系统,https://gitee.com/anxwefndu/supermarket-sales-system
对于第三点,即高级要求并没有进行合适的实现

java语言开发超时销售系统,可以考虑使用控制台或者swing代码界面的方式实现,这里帮你找到一个开源的超市销售管理系统,使用的是swing实现的,应该可以满足你的需求:
[](JAVA+SWING超市销售管理系统开发:https://blog.csdn.net/qq_45241180/article/details/119106392
最后的效果如图:

img


)

java实现简易超市管理系统01(含源码)_java超市销售系统_对方正在长头发_的博客-CSDN博客 java超市管理系统 1.0(含源文件,后续会继续优化~)文章目录java超市管理系统 1.0(含源文件,后续会继续优化~)前言一、确定需求二、确定类、接口、方法实现1.确定类2.确定接口3.确定方法三、敲代码前再分析一波~1.重写equals()吗?2.重写toString吗?3.重写hashCode()吗?4.存储结构的确定四、总结以及源代码前言一个月零零散散的时间学习了java,通过这次“超市管理系统”的练习,希望可以给一同开始学习java的朋友一些参考,更希望大佬们多多指点和批评~一、_java超市销售系统 https://blog.csdn.net/weixin_45510412/article/details/115030110

基于new bing的编写:

import java.io.*;
import java.util.*;

class Goods {
    public String id;    // 商品编号
    public String name;  // 商品名称
    public String category;  // 商品分类
    public double price;  // 商品单价
    public int stock;     // 库存量

    public Goods(String id, String name, String category, double price, int stock) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.price = price;
        this.stock = stock;
    }

    // 用来打印商品信息
    public void display() {
        System.out.printf("%-10s%-18s%-12s%-12.2f%8d\n", id, name, category, price, stock);
    }
}

class Order {
    public String id;   // 订单编号
    public String memberId;  // 会员编号
    public String goodsId;   // 商品编号
    public String goodsName;  // 商品名称
    public String category;   // 商品分类
    public double price;   // 商品单价
    public int amount;   // 商品数量
    public String time;   // 销售时间

    public Order(String id, String memberId, String goodsId, String goodsName, String category, double price, int amount, String time) {
        this.id = id;
        this.memberId = memberId;
        this.goodsId = goodsId;
        this.goodsName = goodsName;
        this.category = category;
        this.price = price;
        this.amount = amount;
        this.time = time;
    }

    // 用来打印订单信息
    public void display() {
        System.out.printf("%-10s%-10s%-10s%-18s%-12s%-12.2f%8d%20s\n", id, memberId, goodsId, goodsName, category, price, amount, time);
    }
}

class Staff {
    public String id;   // 员工编号
    public String name;  // 员工姓名
    public String password;  // 员工密码
    public String phone;   // 联系电话

    public Staff(String id, String name, String password, String phone) {
        this.id = id;
        this.name = name;
        this.password = password;
        this.phone = phone;
    }
}

public class SuperMarketSystem {
    private static Scanner input = new Scanner(System.in);

    // 保存货物库存信息、货物销售信息、工作人员信息
    private static List<Goods> goodsList = new ArrayList<>();
    private static List<Order> orderList = new ArrayList<>();
    private static List<Staff> staffList = new ArrayList<>();

    private static String GOODS_FILE_NAME = "goods.txt";   // 货物库存信息文件名
    private static String ORDER_FILE_NAME = "order.txt";   // 货物销售信息文件名
    private static String STAFF_FILE_NAME = "staff.txt";   // 工作人员信息文件名

    // 加载所有数据
    private static void loadData() throws IOException {
        loadGoods();
        loadOrders();
        loadStaff();
    }

    // 从文件中读取货物库存信息并保存到goodsList中
    private static void loadGoods() throws IOException {
        File file = new File(GOODS_FILE_NAME);
        if (file.exists()) {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] data = line.split(",");
                Goods goods = new Goods(data[0], data[1], data[2], Double.parseDouble(data[3]), Integer.parseInt(data[4]));
                goodsList.add(goods);
            }
            reader.close();
        }
    }

    // 将goodsList中的货物库存信息保存到文件中
    private static void saveGoods() throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(GOODS_FILE_NAME));
        for (Goods goods : goodsList) {
            String line = String.format("%s,%s,%s,%.2f,%d\n", goods.id, goods.name, goods.category, goods.price, goods.stock);
            writer.write(line);
        }
        writer.close();
    }

    // 从文件中读取货物销售信息并保存到orderList中
    private static void loadOrders() throws IOException {
        File file = new File(ORDER_FILE_NAME);
        if (file.exists()) {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] data = line.split(",");
                Order order = new Order(data[0], data[1], data[2], data[3], data[4], Double.parseDouble(data[5]), Integer.parseInt(data[6]), data[7]);
                orderList.add(order);
            }
            reader.close();
        }
    }

    // 将orderList中的货物销售信息保存到文件中
    private static void saveOrders() throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(ORDER_FILE_NAME));
        for (Order order : orderList) {
            String line = String.format("%s,%s,%s,%s,%s,%.2f,%d,%s\n",
                    order.id, order.memberId, order.goodsId, order.goodsName, order.category, order.price, order.amount, order.time);
            writer.write(line);
        }
        writer.close();
    }

    // 从文件中读取工作人员信息并保存到staffList中
    private static void loadStaff() throws IOException {
        File file = new File(STAFF_FILE_NAME);
        if (file.exists()) {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] data = line.split(",");
                Staff staff = new Staff(data[0], data[1], data[2], data[3]);
                staffList.add(staff);
            }
            reader.close();
        }
    }

    // 将staffList中的工作人员信息保存到文件中
    private static void saveStaff() throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(STAFF_FILE_NAME));
        for (Staff staff : staffList) {
            String line = String.format("%s,%s,%s,%s\n", staff.id, staff.name, staff.password, staff.phone);
            writer.write(line);
        }
        writer.close();
    }

    // 根据商品编号查找商品,如果不存在则返回null
    private static Goods findGoods(String id) {
        for (Goods goods : goodsList) {
            if (goods.id.equals(id)) {
                return goods;
            }
        }
        return null;
    }

    // 根据订单编号查找订单,如果不存在则返回null
    private static Order findOrder(String id) {
        for (Order order : orderList) {
            if (order.id.equals(id)) {
                return order;
            }
        }
        return null;
    }

    // 添加新商品到货物库存信息中
    private static void addGoods() throws IOException {
        System.out.println("请输入商品编号:");
        String id = input.nextLine();
        Goods goods = findGoods(id);
        if (goods != null) {   // 商品已经存在,只需修改库存量
            System.out.println("商品已经存在,请输入要添加的库存量:");
            int stock = Integer.parseInt(input.nextLine());
            goods.stock += stock;
            System.out.println("修改成功!");
        } else {   // 商品不存在,需要添加一条新记录
            System.out.println("请输入商品名称:");
            String name = input.nextLine();
            System.out.println("请输入商品分类:");
            String category = input.nextLine();
            System.out.println("请输入商品单价:");
            double price = Double.parseDouble(input.nextLine());
            System.out.println("请输入商品库存量:");
            int stock = Integer.parseInt(input.nextLine());
            Goods newGoods = new Goods(id, name, category, price, stock);
            goodsList.add(newGoods);
            saveGoods();
            System.out.println("添加成功!");
        }
    }

    // 修改商品信息
    private static void modifyGoods() throws IOException {
        System.out.println("请输入要修改的商品编号:");
        String id = input.nextLine();
        Goods goods = findGoods(id);
        if (goods != null) {
            System.out.println("请输入要修改的属性(1-商品名称 2-商品分类 3-商品单价 4-商品库存量):");
            int choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    System.out.println("请输入新的商品名称:");
                    goods.name = input.nextLine();
                    break;
                case 2:
                    System.out.println("请输入新的商品分类:");
                    goods.category = input.nextLine();
                    break;
                case 3:
                    System.out.println("请输入新的商品单价:");
                    goods.price = Double.parseDouble(input.nextLine());
                    break;
                case 4:
                    System.out.println("请输入新的商品库存量:");
                    goods.stock = Integer.parseInt(input.nextLine());
                    break;
                default:
                    System.out.println("无效的选项!");
                    break;
            }
            saveGoods();
            System.out.println("修改成功!");
        } else {
            System.out.println("商品不存在!");
        }
    }

    // 删除商品信息
    private static void deleteGoods() throws IOException {
        System.out.println("请输入要删除的商品编号:");
        String id = input.nextLine();
        boolean found = false;
        for (Iterator<Goods> it = goodsList.iterator(); it.hasNext(); ) {
            Goods goods = it.next();
            if (goods.id.equals(id)) {
                it.remove();
                found = true;
                break;
            }
        }
        if (found) {
            saveGoods();
            System.out.println("删除成功!");
        } else {
            System.out.println("商品不存在!");
        }
    }

    // 显示所有商品信息
    private static void displayAllGoods() {
        System.out.printf("%-10s%-18s%-12s%-12s%8s\n", "编号", "名称", "分类", "单价", "库存量");
        for (Goods goods : goodsList) {
            goods.display();
        }
    }

    // 往购物车中添加商品
    private static void addToCart(List<Order> cart) {
        System.out.println("请输入要购买的商品编号:");
        String id = input.nextLine();
        Goods goods = findGoods(id);
        if (goods != null) {
            System.out.println("请输入要购买的数量:");
            int amount = Integer.parseInt(input.nextLine());
            if (amount <= goods.stock) {
                goods.stock -= amount;
                Order order = new Order(String.format("O%d", orderList.size() + 1), "0", goods.id, goods.name, goods.category, goods.price, amount, getCurrentTime());
                cart.add(order);
                System.out.println("添加成功!");
            } else {
                System.out.println("库存不足!");
            }
        } else {
            System.out.println("商品不存在!");
        }
    }

    // 从购物车中删除商品
    private static void removeFromCart(List<Order> cart) {
        System.out.println("请输入要删除的商品编号:");
        String id = input.nextLine();
        boolean found = false;
        for (Iterator<Order> it = cart.iterator(); it.hasNext(); ) {
            Order order = it.next();
            if (order.goodsId.equals(id)) {
                Goods goods = findGoods(id);
                goods.stock += order.amount;
                it.remove();
                found = true;
                break;
            }
        }
        if (found) {
            System.out.println("删除成功!");
        } else {
            System.out.println("商品不存在!");
        }
    }

    // 显示购物车中的商品信息
    private static void displayCart(List<Order> cart) {
        if (cart.size() > 0) {
            double total = 0;
            System.out.printf("%-10s%-10s%-10s%-18s%-12s%-12s%8s%20s\n", "订单编号", "会员编号", "商品编号", "商品名称", "商品分类", "商品单价", "购买数量", "销售时间");
            for (Order order : cart) {
                order.display();
                total += order.price * order.amount;
            }
            System.out.printf("总金额:%.2f元\n", total);
        } else {
            System.out.println("购物车是空的!");
        }
    }

    // 完成购物,生成订单并保存到文件中,清空购物车
    private static void checkout(List<Order> cart) throws IOException {
        if (cart.size() > 0) {
            displayCart(cart);
            System.out.println("请输入会员编号(不是会员请直接回车):");
            String memberId = input.nextLine();
            for (Order order : cart) {
                order.memberId = memberId;
                orderList.add(order);
            }
            saveGoods();
            saveOrders();
            cart.clear();
            System.out.println("购买成功!");
        } else {
            System.out.println("购物车是空的!");
        }
    }

    // 登录
    private static Staff login() {
        while (true) {
            System.out.println("请输入员工编号:");
            String id = input.nextLine();
            System.out.println("请输入密码:");
            String password = input.nextLine();
            for (Staff staff : staffList) {
                if (staff.id.equals(id) && staff.password.equals(password)) {
                    return staff;
                }
            }
            System.out.println("登录失败,请重新输入!");
        }
    }

    // 显示所有销售记录
    private static void displayAllOrders() {
        System.out.printf("%-10s%-10s%-10s%-18s%-12s%-12s%8s%20s\n", "订单编号", "会员编号", "商品编号", "商品名称", "商品分类", "商品单价", "购买数量", "销售时间");
        for (Order order : orderList) {
            order.display();
        }
    }

    // 显示某个员工的销售记录
    private static void displayStaffOrders(Staff staff) {
        System.out.printf("%-10s%-10s%-10s%-18s%-12s%-12s%8s%20s\n", "订单编号", "会员编号", "商品编号", "商品名称", "商品分类", "商品单价", "购买数量", "销售时间");
        for (Order order : orderList) {
            if (order.memberId.equals(staff.id)) {
                order.display();
            }
        }
    }

    // 获取当前时间
    private static String getCurrentTime() {
        Date date = new Date();
        return String.format("%tF %<tT", date);
    }

    public static void main(String[] args) {
        try {
            loadData();
            Staff staff = login();
            System.out.printf("欢迎%s进入超市管理系统!\n", staff.name);
            while (true) {
                System.out.println("请输入要执行的操作(1-商品管理 2-销售管理 3-查询销售记录 4-退出):");
                int choice = Integer.parseInt(input.nextLine());
                switch (choice) {
                    case 1:   // 商品管理
                        while (true) {
                            System.out.println("请输入要执行的操作(1-添加商品 2-修改商品信息 3-删除商品 4-显示所有商品信息 5-返回):");
                            int op = Integer.parseInt(input.nextLine());
                            switch (op) {
                                case 1:
                                    addGoods();
                                    break;
                                case 2:
                                    modifyGoods();
                                    break;
                                case 3:
                                    deleteGoods();
                                    break;
                                case 4:
                                    displayAllGoods();
                                    break;
                                case 5:
                                    break;
                                default:
                                    System.out.println("无效的选项!");
                                    break;
                            }
                            if (op == 5) {
                                break;
                            }
                        }
                        break;
                    case 2:   // 销售管理
                        List<Order> cart = new ArrayList<>();  // 购物车
                        while (true) {
                            System.out.println("请输入要执行的操作(1-添加商品到购物车 2-从购物车中删除商品 3-显示购物车中的商品信息 4-结账 5-返回):");
                            int op = Integer.parseInt(input.nextLine());
                            switch (op) {
                                case 1:
                                    addToCart(cart);
                                    break;
                                case 2:
                                    removeFromCart(cart);
                                    break;
                                case 3:
                                    displayCart(cart);
                                    break;
                                case 4:
                                    checkout(cart);
                                    break;
                                case 5:
                                    break;
                                default:
                                    System.out.println("无效的选项!");
                                    break;
                            }
                            if (op == 5) {
                                break;
                            }
                        }
                        break;
                    case 3:   // 查询销售记录
                        if (staff.id.equals("S001")) {   // 超级管理员可以查看所有销售记录
                            displayAllOrders();
                        } else {   // 普通员工只能查看自己的销售记录
                            displayStaffOrders(staff);
                        }
                        break;
                    case 4:   // 退出
                        System.out.println("再见!");
                        return;
                    default:
                        System.out.println("无效的选项!");
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}