问题:要求实现商品超市的商品维护模块。

商品维护模块主要包括:商品添加(输入商品编号,名称,价格,数量),商品列表显示,商品入库(输入商品编号,然后提示用户输入入库数量,然后进行修改操作),商品出库(输入商品编号,然后提示用户输入出库数量,然后进行修改操作),修改商品价格(提示用户输入编号,然后输入新价格)。

采用Scanner提示用户进行输入,用System.out.println实现界面。

public class Demo3Redo {

public static void main(String[] args) {
    Map<String, Good> goodsMap = new HashMap<String, Good>() {
        {
            put("GOOD1", new Good("GOOD1", "商品1", 10.0, 30));
            put("GOOD2", new Good("GOOD2", "商品2", 90.0, 20));
            put("GOOD3", new Good("GOOD3", "商品3", 10.3, 11));
            put("GOOD4", new Good("GOOD4", "商品4", 9.0, 10));

        }
    };
    Scanner sc = new Scanner(System.in);
    while (true){
        System.out.println("请输入菜单编号:");
        System.out.println("1 商品展示:");
        System.out.println("2 商品入库:");
        System.out.println("3 商品出库:");
        System.out.println("4 价格修改:");
        System.out.println("5 退出:");
        String flag = sc.nextLine();
        switch (flag) {
            case "1":
                System.out.println("商品编号  商品名称  商品价格  商品库存");
                for (Map.Entry<String, Good> goodEntry : goodsMap.entrySet()) {
                    Good good = goodEntry.getValue();
                    System.out.println(good.getId() + "    " + good.getName() + "    " + good.getPrice() + "    " + good.getInventory());
                }
                break;
            case "2":
                System.out.println("请输入商品编号:");
                String id = sc.nextLine();
                Good good = goodsMap.get(id);
                System.out.println("请输入入库数量:");
                String count = sc.nextLine();
                good.setInventory(good.getInventory() + new Integer(count));
                break;
            case "3":
                System.out.println("请输入商品编号:");
                String idIncre = sc.nextLine();
                Good goodIncre = goodsMap.get(idIncre);
                System.out.println("请输入出库数量:");
                String incre = sc.nextLine();
                int i = goodIncre.getInventory() - new Integer(incre);
                if (i < 0) {
                    i = 0;
                }
                goodIncre.setInventory(i);
                break;
            case "4":
                System.out.println("请输入商品编号:");
                String idPrice = sc.nextLine();
                Good goodPrice = goodsMap.get(idPrice);
                System.out.println("价格:");
                String price = sc.nextLine();
                goodPrice.setPrice(new Double(price));
                break;
            case  "5":
                System.exit(0);
        }
    }

}

}

class Good {
private String id;
private String name;
private Double price;
private int inventory;

public Good(String id, String name, Double price, int inventory) {
    this.id = id;
    this.name = name;
    this.price = price;
    this.inventory = inventory;
}

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 int getInventory() {
    return inventory;
}

public void setInventory(int inventory) {
    this.inventory = inventory;
}

}

如果是想要找人代写作业,建议去某宝