大数据——javaEE

订单类需求
1.用户的基本信息(用户id,用户名称,用户vip等级)
2.商品的基本信息(商品id,商品名称,商品价格,销售数量)
3.订单基本信息(订单id,订单所属用户,订单商品,订单总金额,订单应付金额)

其中的一些算法在order中完成。

用户信息

package exe_ListDemo;

public class user {
	//用户Id
	public String userId;
	//用户名称
	public String userName;
	//用户vip等级
	public String vipLevel;
	
	//有参构造
	public user(String userId,String userName,String vipLevel) {
		this.userId = userId;
		this.userName = userName;
		this.vipLevel = vipLevel;
	}

}

商品信息

package exe_ListDemo;

public class product {
	public String pId;
	public String pname;
	public float price;
	public int number;
	//有参构造
	public product(String pId,String pname,float price,int number) {
		this.pId = pId;
		this.pname = pname;
		this.price = price;
		this.number = number;
	}
	//无参构造
	public product() {
		
	}
	public String toString() {
		String tmp = this.pId + ","+this.pname+","+this.price+","+this.number;
		return tmp;
	}
	

}

订单信息

package exe_ListDemo;

import java.util.ArrayList;

public class order {
	//订单Id
	public String orderId;
	//订单所属用户
	public user user;
	//订单包含的商品
	public ArrayList<product> ps;
	//订单总金额
	public float sum;
	//订单应付金额
	public float paysum;
	//创建订单总金额方法ordersum
	public void ordersum() {
		float sum = 0;
		for(int i = 0;i<this.ps.size();i++) {
			sum += (float) this.ps.get(i).price * this.ps.get(i).number;
		}
		//把总金额的钱数赋给this。sum(类中的sum)
		this.sum = sum;
		System.out.println("订单总金额:"+this.sum);
	}
	
	//创建应付总金额方法orderpay
	public void orderpay() {
		//判断商品总金额是否超过1000来决定是否打折
		float tmp = 0;
		if(this.sum < 1000) {
			tmp = this.sum;
		}
		
		if(this.sum >=1000 && this.sum < 2000) {
			tmp = (float) (this.sum * 0.9);
		}
		
		if(this.sum >= 2000 && this.sum < 3000) {
			tmp = (float) (this.sum * 0.8);
		}
		
		if(this.sum >= 3000) {
			tmp = (float) (this.sum * 0.6);
		}
		
		
		//判断用户信息的vip等级来打折
		if(this.user.vipLevel.equals("黄金vip")) {
			tmp =(float) (tmp * 0.9);
		}
		if(this.user.vipLevel.equals("钻石vip")) {
			tmp =(float) (tmp * 0.8);
		}
		
		if(this.user.vipLevel.equals("至尊vip")) {
			tmp =(float) (tmp * 0.7);
		}
		//把打完折的钱数赋给paysum
		this.paysum = tmp;
		System.out.println("应付总金额:"+this.paysum);
	}
	

}

订单测试

package exe_ListDemo;

import java.util.ArrayList;

public class order_test {
	public static void main(String[] args) {
		order o1 = new order();
		//订单编号
		o1.orderId = "1";
		//用户信息
		user u1 = new user("1","楚行云","钻石vip");
		o1.user = u1;
		//商品信息
		ArrayList<product> ps1 = new ArrayList<product>();
		product p1 = new product("1","卫生纸",20.5f,5);
		product p2 = new product("2","雪糕",2.5f,10);
		product p3 = new product("3","啤酒",10.5f,20);
		product p4 = new product("1","电脑",3000,2);
		
		ps1.add(p1);
		ps1.add(p2);
		ps1.add(p3);
		ps1.add(p4);
		//把商品信息赋给order的商品信息ps
		o1.ps = ps1;
		System.out.println(o1.ps);
		
		//商品总金额
		o1.ordersum();
		//应付总金额
		o1.orderpay();
		
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值