要求实现商品超市的商品维护模块。商品维护模块主要包括:商品添加(输入商品编号、名称、价格、数量)、商品列表展示、商品入库(输入商品编号,然后提示用户输入入库数量,然后进行修改操作)、商品出库(输入商品编号,然后提示用户输入出库数量,然后进行修改操作)、修改商品价格(提示用户输入编号,然后输入新价格)。
采用Scanner提示用户进行输入,用System.out.println实现界面。
Scanner s=new Scanner(System.in);
s.nextInt();
有没有老哥知道这个要怎么写呀
要求实现商品超市的商品维护模块。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 高级日报开发工程师 2021-12-21 16:19关注
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;
}
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 关于#Java#的问题,如何解决?
- ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
- ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
- ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
- ¥15 cmd cl 0x000007b
- ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
- ¥500 火焰左右视图、视差(基于双目相机)
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化