大数据——javaEE

需求:
1.列出生活用品的属性(编号,名称,价格,卖了多少件)
2.求出销售总额
3.求出销售最高的商品`

package exe_ListDemo;

public class exe_product {
	public String pId;  //商品编号
	public String pName;  //商品名称
	public float pPrice;  //商品价格
	public int Number;   //商品数量
	
	//含参构造
	public exe_product(String pId,String pName,float string,int Number) {
		this.pId = pId;
		this.pName = pName;
		this.Number = Number;
		this.pPrice = string;
	}
	public String toString() {
	String tmp = this.pId+","+this.pName+","+this.pPrice+","+this.Number;
	return tmp;
    }
	//无参构造,个人觉得用含参构造方法简单
	public exe_product() {
		
	}

}

`

package exe_ListDemo;

import java.util.ArrayList;

public class exe_listDemo {
	public static void main(String[] args) {
		exe_product p1 = new exe_product("1", "牙刷", 10.5f, 20);
		
		exe_product p2 = new exe_product("2", "电脑", 5000.0f, 3);
		
		exe_product p3 = new exe_product("3", "洗衣机", 3000.0f, 10);
		
		exe_product p4 = new exe_product("4", "毛巾", 20.0f, 8);
		//new一个集合来装product的信息
		ArrayList<exe_product> ps = new ArrayList<exe_product>();
		//用add方法将这些商品信息放入集合中
		ps.add(p1);
		ps.add(p2);
		ps.add(p3);
		ps.add(p4);
		
		System.out.println(ps);
		
		
		//计算商品的总金额
		float sum = 0;
		for(int i = 0;i<ps.size();i++) {
			sum += ps.get(i).pPrice * ps.get(i).Number;
			
		}
		System.out.println("商品总金额是:"+sum);
		
		//计算销售总额最高的商品
		exe_product tmp= ps.get(0);
		for(int i = 0;i < ps.size();i++) {
			if(tmp.pPrice * tmp.Number < ps.get(i).pPrice * ps.get(i).Number) {
				tmp = ps.get(i);
			}
		}
		System.out.println("销售总额最高的商品是:"+tmp);

		
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值