qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-高级专业版🔥

用java代码写一个商城管理

时间2023-04-30 01:30:47 提问来自 上海市上海市 的网友 分类创作 浏览262
import java.util.*; public class ShoppingMallManager { public static void main(String[] args) { Map<String, Integer> productMap = new HashMap<>(); // 商品名称与库存量的映射 Map<String, Integer> priceMap = new HashMap<>(); // 商品名称与价格的映射 Scanner scanner = new Scanner(System.in); while (true) { System.out.println("请输入要进行的操作:1、查看所有商品 2、新增商品 3、修改库存 4、退出"); int op = scanner.nextInt(); switch (op) { case 1: // 查看所有商品 System.out.println("当前所有的产品如下:"); Set<String> keyset = productMap.keySet(); // 获取所有键的集合 for (String key : keyset) { // 遍历键集合 int count = productMap.get(key); // 根据键获取对应的库存量 int price = priceMap.get(key); // 根据键获取对应的价格 System.out.println("产品名称:" + key + ",数量:" + count + ",单价:" + price); } break; case 2: // 新增一个产品 System.out.println("请输入要新加入到产城中的产在信息[name count price]"); String line= scanner .nextLine(); String[] arr= line .split("\\s+"); String name= arr[0]; int count= Integer .parseInt(arr[1]); int price= Integer .parseInt(arr[2]); productMap .put(name ,count ); priceMap .put(name ,price ); break; case 3: // 修改一个产在数量 System .out .println ("请辜九条要修改数量的交昵 [name num]") ; line=scanner .nextLine() ; arr=line ;split ("\\s+") ; name=arr[0] ; count+=Integer .parseInt (arr[1]) ; if (count <0 ){ Systenm println ("Error! The number of the product cannot be negative!" ) ; continue ; } produtcMab

点击这里,进行内容创作

创作工场 免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!

上一篇 以重生为题材写一篇小说 下一篇 法国的政党政治结构及其在二十一世纪初的转变