要求实现商品超市的商品维护模块。商品维护模块主要包括:商品添加(输入商品编号、名称、价格、数量)、商品列表展示、商品入库(输入商品编号,然后提示用户输入入库数量,然后进行修改操作)、商品出库(输入商品编号,然后提示用户输入出库数量,然后进行修改操作)、修改商品价格(提示用户输入编号,然后输入新价格)。
采用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无用
悬赏问题
- ¥150 如图所示配置eNSP
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上
- ¥15 c程序不知道为什么得不到结果
- ¥15 键盘指令混乱情况下的启动盘系统重装