java商品管理系统

package shangpin;

public class Goods {
    private String id;//商品编号
    private String name;//名称
    private double price;//价格
    private String miaoshu;//描述

    @Override
    //重写toString
    public String toString() {
        return "商品信息:"+id+","+name+","+price+","+miaoshu;
    }

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

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getMiaoshu() {
        return miaoshu;
    }

    public void setMiaoshu(String miaoshu) {
        this.miaoshu = miaoshu;
    }
}

package shangpin;

import java.util.List;

public class Zsgc {
    //添加,删除,修改,单查询,展示全查
    //添加(上架商品)
    public static boolean add(Goods go, List<Goods> dd){
        boolean f = true;
        for (Goods bianhao : dd){
            if (go.getId().equals(bianhao.getId())){
                f = false;
                break;
            }
        }
        if (f){
            dd.add(go);
        }
        return f;
    }

    //修改(调整价格)
    public static boolean modify(Goods go,List<Goods> dd){
        boolean f = false;
        for (Goods bianhao : dd){
            if (go.getId().equals(bianhao.getId())){
                f = true;
                bianhao.setName(go.getName());
                bianhao.setPrice(go.getPrice());
                bianhao.setMiaoshu(go.getMiaoshu());
                break;
            }
        }
        return f;
    }

    //删除(下架商品 )
    public static boolean delete(String id,List<Goods> dd){
        boolean f = false;
        for (Goods bianhao : dd){
            if (bianhao.getId().equals(id)){
               dd.remove(bianhao);
               f = true;
               break;
            }
        }
        return f;
    }

    //单查
    public static Goods select(String id,List<Goods> dd){
        Goods g = null;
        for (Goods bianhao : dd){
            if (bianhao.getId().equals(id)){
                g = bianhao;
                break;
            }
        }
        return g;
    }

    //展示(商品列表)
    public static void show(List<Goods> dd){
        for (Goods bianhao : dd){
            System.out.println(bianhao);
        }
    }
}

package shangpin;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Spin {
    //添加静态字段
    static List<Goods> dd = new ArrayList<Goods>();
    static Scanner read = new Scanner(System.in);

    public static void main(String[] args) {
        dd.add(new Goods("11","汽水",3,"气泡水"));
        dd.add(new Goods("12","饼干",8,"饿了就吃"));
        dd.add(new Goods("13","辣条",5,"卫龙"));

        //定义数据类型
        int n = 0;
        String id,name,miaoshu;
        double price;
        Goods g;
        boolean f;

        do {
            System.out.println("欢迎使用999商品管理系统");
            System.out.println("---商品列表请输入:1---");
            System.out.println("---上架商品请输入:2---");
            System.out.println("---下架商品请输入:3---");
            System.out.println("---调整商品请输入:4---");
            System.out.println("---单查某个商品请输入:5---");
            System.out.println("---退出:0----");
            System.out.print("请选择:");

            n = read.nextInt();
            switch (n) {
                case 1:
                    System.out.println("所有商品列表为:");
                    System.out.println("-------编号 名称 价格 描述");
                    Zsgc.show(dd);
                    break;
                case 2:
                    System.out.println("请输入新商品编号:");
                    id = read.next();
                    System.out.println("请输入新商品名称:");
                    name = read.next();
                    System.out.println("请输入新商品价格:");
                    price = read.nextDouble();
                    System.out.println("请输入新商品描述:");
                    miaoshu = read.next();

                    g = new Goods(id,name,price,miaoshu);
                    f = Zsgc.add(g,dd);
                    if (f) {
                        System.out.println("上架成功");
                    }else {
                        System.out.println("上架失败");
                    }
                    break;
                case 3:
                    System.out.println("请输入要删除的商品编号:");
                    id = read.next();
                    f = Zsgc.delete(id,dd);
                    if (f){
                        System.out.println("删除成功");
                    }else {
                        System.out.println("删除失败");
                    }
                    break;
                case 4:
                    System.out.println("请输入要修改的商品编号");
                    id = read.next();
                    System.out.println("请输入要修改的商品名称");
                    name = read.next();
                    System.out.println("请输入要修改的商品价格");
                    price = read.nextDouble();
                    System.out.println("请输入要修改的商品描述");
                    miaoshu = read.next();

                    g = new Goods(id,name,price,miaoshu);
                    f = Zsgc.modify(g,dd);
                    if (f) {
                        System.out.println("修改成功");
                    }else {
                        System.out.println("修改失败");
                    }
                    break;
                case 5:
                    System.out.println("请输入要查询的商品编号");
                    id = read.next();
                    g = Zsgc.select(id,dd);
                    if (g != null){
                        System.out.println(g);
                    }else {
                        System.out.println("没有此商品");
                    }
                    break;

            }
        }while (n != 0);
    }
}


运行结果:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  • 13
    点赞
  • 173
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
根据提供的引用内容,我无法找到关于商品交易信息管理的具体信息。但是,我可以为您提供一些关于商品交易信息管理的一般概念和方法。 商品交易信息管理是指通过信息化系统来管理和处理商品交易相关的信息。在Java开发中,可以使用Java编程语言和相关的技术来实现商品交易信息管理系统。 以下是一个简单的Java代码示例,演示如何创建一个商品类和一个交易类,并实现商品交易信息的管理: ```java // 商品类 public class Product { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } // 省略getter和setter方法 } // 交易类 public class Transaction { private Product product; private int quantity; public Transaction(Product product, int quantity) { this.product = product; this.quantity = quantity; } // 省略getter和setter方法 } // 商品交易信息管理类 public class ProductTransactionManager { private List<Transaction> transactions; public ProductTransactionManager() { this.transactions = new ArrayList<>(); } public void addTransaction(Transaction transaction) { transactions.add(transaction); } public List<Transaction> getTransactions() { return transactions; } } // 示例用法 public class Main { public static void main(String[] args) { Product product1 = new Product("Apple", 2.5); Product product2 = new Product("Banana", 1.5); Transaction transaction1 = new Transaction(product1, 3); Transaction transaction2 = new Transaction(product2, 5); ProductTransactionManager manager = new ProductTransactionManager(); manager.addTransaction(transaction1); manager.addTransaction(transaction2); List<Transaction> transactions = manager.getTransactions(); for (Transaction transaction : transactions) { System.out.println("Product: " + transaction.getProduct().getName()); System.out.println("Quantity: " + transaction.getQuantity()); System.out.println("Total Price: " + transaction.getProduct().getPrice() * transaction.getQuantity()); System.out.println("--"); } } } ``` 这段代码演示了如何创建商品类和交易类,并使用商品交易信息管理类来管理交易信息。您可以根据实际需求进行扩展和修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值