使用Java怎么创建一个订单类

  介绍

使用Java怎么创建一个订单类?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

<强>需求描述

<李>

定义一个类,描述订单信息

<李>

订单id

<李>

订单所属用户(用户对象)

<李>

订单所包含的商品(不定数量个商品对象)

<李>

订单总金额

<李>

订单应付金额:

<李>

总金额500 ~ 1000,打85折折

<李>

总金额1000 ~ 1500,打80折折

<李>

总金额1500 ~ 2000,打70折折

<李>

总金额超过2000,打65折折

在此基础上,还要看用户的贵宾等级

<李>

用户贵宾等级为:一般会员,则折上折:95

<李>

用户贵宾等级为:中级会员,则折上折:90

<李>

用户贵宾等级为:高级会员,则折上折:80

<强>代码实现

用户。java

package  cn.test.logan.day04;/* *   ,*用户类   ,*包含信息项目:用户ID,用户名,用户会员等级   ,* @author 秦   ,*   ,*/public  class  User  {//,才能用户ID   public 才能;String  CustId;   ,,,,//,才能用户名   public 才能;String  CustName;   ,,,,//,才能用户会员等级   public 才能;String  CustLevel;   ,,,,   public 才能;用户(),{   ,,,,   ,,}   ,,   public 才能;用户(String  CustId String  CustName, String  CustLevel), {   ,,,this.CustId =, CustId;   ,,,this.CustName =, CustName ;   ,,,this.CustLevel =, CustLevel ;   ,,}   }

产品。java

package  cn.test.logan.day04;/* *   ,*商品类   ,*包含:商品ID、商品名称,商品价格,商品数量   ,* @author 秦   ,*   ,*/public  class  Product  {   ,,//才能,商品ID   public 才能String  pId;   ,,//才能,商品名称   public 才能;String  pName;   ,,//商才能品价格   public 才能;float 价格;   ,,//才能,商品数量   public 才能int 数量;   ,,   public 才能;产品(),{   ,,,,   ,,}   ,,   public 才能;产品(String  pId, String  pName, float 价格,int 数字),{   ,,,this.pId =, pId;   ,,,this.pName =, pName;   ,,,this.price =,价格;   ,,,this.number =,数量;   ,,}   }

订单。java

package  cn.test.logan.day04;      import  java.util.ArrayList;/* *   ,*订单类   ,*包含:订单ID、订单所属用户,订单所包含的商品,订单总金额,订单应付金额   ,* 500 - 1000,- - - - - -→8.5折   ,* 1000 - 1500,- - - - - -→8折   ,* 1500 - 2000,- - - - - -→7折   2000年,*以上,- - - - - -→6.5折   ,*,如果是会员,那么可以基于以上折扣继续折扣   ,*,一般会员:9.5折   ,*,中级会员:9折   ,*,高级会员:8折   ,* @author 秦   ,*   ,*/public  class  Order  {//,才能订单ID    public 才能;String  ordId;   ,,//,才能订单所属用户   public 才能User 用户;   ,,//,才能订单所包含的商品(多个商品,使用ArrayList)   public 才能;ArrayList< Product>, pds;   ,,//,才能订单总金额   public 才能;float  ordAllAmt;   ,,//,才能订单应付金额   public 才能;float  payAmt;   ,,//才能,计算总金额的方法   public 才能;void  setAllAmt (), {   ,,,float  sum =, 0;   ,,,(int 我=0;i< this.pds.size();我+ +),{   ,,,,,sum  +=this.pds.get .price  *, this.pds.get .number;   ,,,}   ,,,this.ordAllAmt =,总和;   ,,}   ,,//才能,计算实付金额   public 才能;void  setPayAmt (), {   ,,,float  tmp =, this.ordAllAmt;   ,,,,   ,,,//,根据总金额进行折扣   ,,,如果(this.ordAllAmt 祝辞=,500,,,,this.ordAllAmt  & lt;, 1000), {   ,,,,,tmp =, this.ordAllAmt  *, 0.85 f;   ,,,}   ,,,如果(this.ordAllAmt 祝辞=,1000,,,,this.ordAllAmt  & lt;, 1500), {   ,,,,,tmp =, this.ordAllAmt  *, 0.8 f;   ,,,}   ,,,如果(this.ordAllAmt 祝辞=,1500,,,,this.ordAllAmt  & lt;, 2000), {   ,,,,,tmp =, this.ordAllAmt  *, 0.7 f;   ,,,}   ,,,如果(this.ordAllAmt 祝辞=,2000),{   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

使用Java怎么创建一个订单类