欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java小白-2运算符---超市购物小票案例

程序员文章站 2022-05-18 16:33:38
...

Java小白-2运算符---超市购物小票案例

简化题目

欢迎光临
品名 售价 数量 金额
----------------------------------
a    1.1* 1    
(001) = 1.1
b    2.2* 2
(002) = 4.4    
c    3.3* 3
(003) = 9.9    
-----------------------------------
3项商品 共计:6件
总计:15.4
凭此小票换取发票!


//Name Price * Number
//Id = Money
//--------------------
//--------------------
//goodsItem goodsNumber
//goodsMoney

分析:

  • 品名:Name,String
  • 商品编号:Id,String
  • 售价:Price,double
  • 数量:Number,int
  • 金额:Money,double
  • --------------------------
  • _项商品:goodsItem,int
  • 共计:_件:goodsNumber,int
  • 总计:goodsMoney,double
public class SuperMarketTicket {
	public static void main(String[] args) {
		//定义
		String aName = "a";
		String aId = "(001)";
		double aPrice = 1.1;
		int aNumber = 1;
		double aMoney = aPrice * aNumber;
		
		String bName = "b";
		String bId = "(002)";
		double bPrice = 2.2;
		int bNumber = 2;
		double bMoney = bPrice * bNumber;
		
		String cName = "c";
		String cId = "(003)";
		double cPrice = 3.3;
		int cNumber = 3;
		double cMoney = cPrice * cNumber;
		
		//计算:_项商品
		int goodsItem = 3;
		//计算:共计:_件
		int goodsNumber = aNumber + bNumber + cNumber;
		//计算:总计:_
		double goodsMoney = aMoney + bMoney + cMoney;
		
		//打印
		//票头
		System.out.println("欢迎光临");
		System.out.println("品名   售价数量金额");
		System.out.println("------------------------------------------------");
		
		//票体
		System.out.println(aName +aId + "" +aPrice + "" + aNumber + "" +aMoney);
		System.out.println(bName +bId + "" +bPrice + "" + bNumber + "" +bMoney);
		System.out.println(cName +cId + "" +cPrice + "" + cNumber + "" +cMoney);
		
		//票脚
		System.out.println("" + goodsItem + "项商品共计:" + goodsNumber + "件";
		System.out.println("总计:" + goodsMoney);
		System.out.println("凭此小票换取发票!");
	}
}

//自java帮帮-悟空教程

相关标签: java 运算符