package ord; import java.util.ArrayList; public class order { public String orderid; public user user; public ArrayList<product> pdls; public float ordernum; public float ordmon; public double acfee; public double tolmon; public void getdeunt() { float sum=0; for(int i=0;i<this.pdls.size();i++) { sum +=this.pdls.get(i).price *this.pdls.get(i).num; } this.ordmon = sum; } public void setmon() { double tmp=0; if(this.ordmon>=1000 & this.ordmon<2000) { tmp=0.98; } else if(this.ordmon>=2000 & this.ordmon <3000) { tmp=0.95; } else if(this.ordmon>=3000) { tmp=0.90; } //user level double acfee=0; if(this.user.level.equals("gold")) { acfee=0.98*tmp; } else if(this.user.level.equals("dia")) { acfee = 0.96*tmp; } else if(this.user.level.equals("super")) { acfee=0.92*tmp; } this.acfee=acfee; } public void acmon() { double tmon; tmon =this.acfee * this.ordmon; this.tolmon=tmon; } }
package ord; public class product { String orderid; String pron; double price; Integer num; public product(String orderid,String name,double price,int num) { this.orderid =orderid; this.pron = name; this.price =price; this.num =num; } }
package ord; public class user { String usid; String usna; String level; public user(String usid,String usna,String level) { this.usid =usid; this.usna=usna; this.level=level; } }
package ord; import java.util.ArrayList; public class ordertt { public static void main(String []args) { order o1 =new order(); user user=new user("a","li","gold"); o1.user =user; ArrayList<product> pdfs = new ArrayList<product>(); product p1 = new product("1","ab",11.1,200); product p2 = new product("2","abb",10,200); pdfs.add(p1); pdfs.add(p2); o1.pdls = pdfs; o1.getdeunt(); o1.setmon(); o1.acmon(); System.out.print(o1.tolmon); } }
原文:https://www.cnblogs.com/Dai-py/p/10790945.html