欢迎光临散文网 会员登陆 & 注册

商品管理(查询出售等)

2022-12-21 12:20 作者:酸奶公园  | 我要投稿

package sanjixiangmu;




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,"非常辣"));

        dd.add(new Goods("111","汽水",3,"有气还有水"));

        dd.add(new Goods("112","饼干",8,"很干"));

      

        

        int n = 0;

        String id,name,miaoshu;

        double price;

        Goods g;

        boolean f;


        do {

            System.out.println("欢迎使用酸奶公园商品管理系统");

            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.println("了解更多+V:Suannai_yogurT");

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

    }

}

package sanjixiangmu;




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




public class Goods {

    private String id;

    private String name;

    private double price;

    private String miaoshu;


    @Override

    

    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;

    }

}

















商品管理(查询出售等)的评论 (共 条)

分享到微博请遵守国家法律