商场笔记本电脑库存案例代码实现(java基础)

具体实现功能:

具体代码实现:

package day01;


public class Shopping{
	public static void main(String[] args){
		//输出表头固定数据
		System.out.println("------------------商场库存清单------------------");
		System.out.println("品牌型号                                    尺寸                      价格               库存数");
		//定义表格中的数据变量
		//品牌型号,String, 尺寸,价格 double  库存int
		String MacBrand = "AppleMacBook Air";
		double MacSize = 13.3;
		double MacPrice = 7388.00;
		int    MacCount = 6;
		
		String LenovoBrand = "Y7000P";
		double LenovoSize = 15.6;
		double LenovoPrice = 8099.00;
		int    LenovoCount = 10;
		
		String AsusBrand = "飞行堡垒7";
		double AsusSize = 15.6;
		double AsusPrice = 6889.00;
		int    AsusCount = 17;
		
		
		String RazerBrand = "雷蛇灵刃15";
		double RazerSize = 15.6;
		double RazerPrice = 9999.00;
		int    RazerCount = 12;
		
		String HpBrand = "暗影精灵5";
		double HpSize = 15.6;
		double HpPrice = 7299.00;
		int    HpCount = 8;
		
		String MECHREVOBrand = "深海泰坦X3";
		double MECHREVOSize = 17.3;
		double MECHREVOPrice = 7799.00;
		int    MECHREVOCount = 15;
		
		String DellBrand = "游匣G3";
		double DellSize = 15.6;
		double DellPrice = 6599.00;
		int    DellCount = 20;
		
		
		//商品信息变量进行打印,变量之间加入一定的字符串空格
		System.out.println(MacBrand+"    "+MacSize+"      "+MacPrice+"      "+MacCount);
		System.out.println(LenovoBrand+"              "+LenovoSize+"      "+LenovoPrice+"      "+LenovoCount);
		System.out.println(AsusBrand+"             "+AsusSize+"      "+AsusPrice+"      "+AsusCount);
		System.out.println(RazerBrand+"            "+RazerSize+"      "+RazerPrice+"      "+RazerCount);
		System.out.println(HpBrand+"             "+HpSize+"      "+HpPrice+"      "+HpCount);
		System.out.println(MECHREVOBrand+"            "+MECHREVOSize+"      "+MECHREVOPrice+"      "+MECHREVOCount);
		System.out.println(DellBrand+"               "+DellSize+"      "+DellPrice+"      "+DellCount);
		
		
		
		//计算库存总数,所有商品数量库存求和
		int totalCount = MacCount+LenovoCount+AsusCount+RazerCount+HpCount+MECHREVOCount+DellCount;
		//计算所有商品库存的总金额,每个商品价格*库存数
		double totalMoney = MacCount*MacPrice + LenovoPrice*LenovoCount + AsusCount*AsusPrice 
				+ RazerPrice*RazerCount + HpPrice*HpCount + MECHREVOPrice*MECHREVOCount + DellPrice*DellCount;
		//输出表格底部
		System.out.println("总库存数: "+totalCount);
		System.out.println("商品库存总金额: "+totalMoney);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_39672140/article/details/97498590
今日推荐