0
点赞
收藏
分享

微信扫一扫

java 库存出入货物程序设计

洒在心头的阳光 2022-04-05 阅读 67
java

此案例编写一个模拟商品入库的程序(里面包含 品牌型号,尺寸,价格,配置,库存,总价),在控制台输入数量,便可以得到商品的总价格。(这里华为,小米为示例)

此程序只有一个Test类

Test类

这里建议test1开头字母为大写

import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        //准备一些华为手机信息
       String huaWeiBrand="华为手机";
       double huaWeiSize=5.5;
       double huaWeiPrice=3688.88;
       String huaWeiConfig="8+128g 全面刘海屏";
        System.out.println("品牌:"+huaWeiBrand);
        System.out.println("尺寸:"+huaWeiSize);
        System.out.println("价格:"+huaWeiPrice);
        System.out.println("配置:"+huaWeiConfig);
        Scanner sc  = new Scanner(System.in);
        System.out.println("请输入"+huaWeiBrand+"的库存");
        int huaWeiCount = sc.nextInt();
        double huaWeiMoney=huaWeiCount*huaWeiPrice;
        System.out.println("库存"+huaWeiBrand+"的金额"+huaWeiMoney);

        //准备一些小米手机的信息
        String XMBrand="小米手机";
        double XMSize=5.0;
        double XMPrice=2988.88;
        String XMConfig="4+64g 全面屏";
        System.out.println("品牌:"+XMBrand);
        System.out.println("尺寸:"+XMSize);
        System.out.println("价格:"+XMPrice);
        System.out.println("配置:"+XMConfig);
        System.out.println("请输入"+XMBrand+"的库存");
        int XMCount = sc.nextInt();
        double XMMoney=XMCount*XMPrice;
        System.out.println("库存"+XMBrand+"的金额"+XMMoney);

        System.out.println("--------------库存清单----------------");
        //"\t"制表符 "\t"调整表格=tab键
        System.out.println("品牌型号\t 尺寸\t价格\t配置\t库存\t金额\t");
        System.out.println(huaWeiBrand+"\t"+huaWeiSize+"\t"+huaWeiPrice+"\t"+huaWeiConfig+"\t"+huaWeiCount+"\t"+huaWeiMoney);
        System.out.println(XMBrand+"\t"+XMSize+"\t"+XMPrice+"\t"+XMConfig+"\t"+XMCount+"\t"+XMMoney);
        System.out.println("-------------------------------------");
        System.out.println("总库存"+(huaWeiCount+XMCount));
        System.out.println("总金额"+(huaWeiMoney+XMMoney));

    }
    }

成果展示

库存清单这里如果觉得不太好看,可以在 代码中调节,添加制表符(因为本人太懒,所以不想调节了)。

举报

相关推荐

0 条评论