Java【案例2-1】 库房出入货物程序设计

案例介绍:现要对华为和小米两种手机产品进行入库,本案例要求编写一个模拟商品入库的程序,可以在控制台输入入库商品的数量,最后打印出仓库中所有商品详细信息以及所有商品的总库存数和库存商品总金额。

商品信息如下:

  1. 品牌型号
  2. 尺寸
  3. 价格
  4. 配置
  5. 库存
  6. 总价
     public class Main {
        public static void main(String[] args) {
            /*
     	     *现在有两款手机华为与小米需要做入库处理,我们需要编写一个程序来实现商品的入库,
             *入库完成后,打印入库商品的详细信息并计算出入库商品的数量与入库商品总金额。
     	     */
            //华为手机
           String  huaweiBrand ="华为";
           double huaweiSize=5.5;
           double huaweiPrice=3688.88;
           String  huaweiConfig="8+128g 全面刘海屏";
           //小米手机
           String  xiaomiBrand ="小米";
           double xiaomiSize=5.0;
           double xiaomiPrice=2988.88;
           String  xiaomiConfig="4+64g 全面屏";
           //华为手机入库
           System.out.println("品牌型号:"+huaweiBrand);
           System.out.println("尺寸:"+huaweiSize);
           System.out.println("价格:"+huaweiPrice);
           System.out.println("配置:"+huaweiConfig);
           Scanner sc1 = new Scanner(System.in);
           System.out.println("请输入"+huaweiBrand+"手机的库存");
           int huanweiCount=sc1.nextInt();
           double huaweiTotal=huanweiCount*huaweiPrice;
           System.out.println("库存"+huaweiBrand+"手机的总金额:"+huaweiTotal);
           //小米手机入库
           System.out.println("品牌型号:"+xiaomiBrand);
           System.out.println("尺寸:"+xiaomiSize);
           System.out.println("价格:"+xiaomiPrice);
           System.out.println("配置:"+xiaomiConfig);
           System.out.println("请输入"+xiaomiBrand+"手机的库存");
           int xiaomiCount=sc1.nextInt();
           double xiaomiTotal=xiaomiCount*xiaomiPrice;
           System.out.println("库存"+xiaomiBrand+"手机的总金额:"+xiaomiTotal);
           //库存清单
           System.out.println("------------库存清单------------");
           System.out.println("品牌型号   尺寸   价格       配置             库存数量   总价");
           System.out.println(huaweiBrand+"      "+huaweiSize+"   "+huaweiPrice+"    "+huaweiConfig+"   "+huanweiCount+"     "+huaweiTotal);
           System.out.println(xiaomiBrand+"      "+xiaomiSize+"   "+xiaomiPrice+"    "+xiaomiConfig+"       "+xiaomiCount+"     "+xiaomiTotal);
           System.out.println("---------------------------------");
           int total=huanweiCount+xiaomiCount;
           double totalMoney=huaweiTotal+xiaomiTotal;
           //总库存数量与库存总价
            System.out.println("总库存:"+total);
            System.out.println("库存总价:"+totalMoney+"¥");
        }
      };

    运行结果为

 

  • 20
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我会为您编一个Python程序来模拟商品入库的流程。以下是程序代码: ```python class Product: def __init__(self, brand, model, size, price, configuration, stock): self.brand = brand self.model = model self.size = size self.price = price self.configuration = configuration self.stock = stock self.total_price = price * stock class Inventory: def __init__(self): self.products = [] def add_product(self, product): self.products.append(product) def print_inventory(self): total_stock = 0 total_value = 0 for product in self.products: total_stock += product.stock total_value += product.total_price print(f"品牌型号: {product.brand} {product.model}, 尺寸: {product.size}, 价格: {product.price}, 配置: {product.configuration}, 库存: {product.stock}, 总价: {product.total_price}") print(f"库存商品总数: {total_stock}, 库存商品总金额: {total_value}") if __name__ == '__main__': inventory = Inventory() # 添加华为手机 huawei_stock = int(input("请输入华为手机入库数量:")) huawei = Product("华为", "P30", "6.1英寸", 3988, "6GB+128GB", huawei_stock) inventory.add_product(huawei) # 添加小米手机 xiaomi_stock = int(input("请输入小米手机入库数量:")) xiaomi = Product("小米", "MI 9", "6.39英寸", 2999, "6GB+128GB", xiaomi_stock) inventory.add_product(xiaomi) # 打印仓库所有商品信息 inventory.print_inventory() ``` 您可以通过在控制台输入华为小米手机入库数量来运行程序。程序会创建 `Product` 和 `Inventory` 类,用于存储商品信息和管理商品库存。在程序运行过程中,您将被提示输入每种手机入库数量。最后,程序将打印出仓库中所有商品的详细信息以及所有商品的总库存数和总金额。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值