admin管理员组

文章数量:1552156

 代码案例:

package cn.itcast.chapterdemo;

/*商品库存清单案例
 * 变量的形式对商品的数据保存
 * 品牌,尺寸大小,价格,配置,库存数量
 * 三个品牌:苹果,联想thinkpad,华硕
 */
public class Test02 {
	public static void main(String[] args) {
		// 定义苹果电脑的属性
		String macBrand = "MacBookAir";// brand:品牌
		double macSize = 13.3;
		double macPrice = 6988.88;
		String macConfig = "i5处理器4GB128GB固态硬盘";// config:配置
		int macCount = 5;
		// 定义联想电脑
		String thinkpadBrand = "ThinkPadT450";
		double tinkpadSize = 14.0;
		double thinkpadPrice = 5999.99;
		String thinkpadConfig = "i5处理器4GB500GB硬盘";
		int thinkpadConut = 10;
		// 定义华硕电脑
		String ASUSBBrand = "ASUS-FL5800";
		double ASUSBSize = 15.6;
		double ASUSBPrice = 4999.90;
		String ASUSBConfig = "i7处理器4GB内存128GB固态硬盘";
		int ASUSBConut = 18;

		// 列表的顶部
		System.out.println("------------------------商品库存清单------------------------");
		System.out.println(
				"品牌型号                     尺寸                 价格                  配置                                                        库存数");
		// 列表中部
		System.out.println(
				macBrand + "   " + macSize + "    " + macPrice + "   " + macConfig + "            " + macCount);
		// 快捷键ctrl+alt+上键:复制当前行到上一行
		System.out.println(thinkpadBrand + " " + tinkpadSize + "    " + thinkpadPrice + "   " + thinkpadConfig
				+ "                  " + thinkpadConut);

		System.out.println(
				ASUSBBrand + "  " + ASUSBSize + "    " + ASUSBPrice + "    " + ASUSBConfig + "   " + ASUSBConut);
		// 设置分界线
		System.out.println("---------------------------------------------------------");
		// 定义库存总数和总金额
		int total = macCount + thinkpadConut + ASUSBConut;
		double moneyTotal = macPrice * macCount + thinkpadPrice * thinkpadConut + ASUSBPrice * ASUSBConut;
		// 列表底部
		System.out.println("库存总数是: " + total);
		System.out.println("库存总金额是: " + moneyTotal);
	}

}

 打印结果:

------------------------商品库存清单------------------------
品牌型号                     尺寸                 价格                  配置                                                        库存数
MacBookAir   13.3    6988.88   i5处理器4GB128GB固态硬盘            5
ThinkPadT450 14.0    5999.99   i5处理器4GB500GB硬盘                  10
ASUS-FL5800  15.6    4999.9    i7处理器4GB内存128GB固态硬盘   18
---------------------------------------------------------
库存总数是: 33
库存总金额是: 184942.5

本文标签: 清单库存案例代码商品