| 1 16 package com.tctest.spring.integrationtests.tests.sellitem; 17 18 import java.io.Serializable ; 19 20 import org.springframework.core.style.ToStringCreator; 21 22 public class Sale implements Serializable { 23 24 private double price; 25 26 private int itemCount; 27 28 private String category; 29 30 private boolean shipping; 31 32 private String shippingType; 33 34 public String getCategory() { 35 return category; 36 } 37 38 public void setCategory(String category) { 39 this.category = category; 40 } 41 42 public int getItemCount() { 43 return itemCount; 44 } 45 46 public void setItemCount(int itemCount) { 47 this.itemCount = itemCount; 48 } 49 50 public double getPrice() { 51 return price; 52 } 53 54 public void setPrice(double price) { 55 this.price = price; 56 } 57 58 public boolean isShipping() { 59 return shipping; 60 } 61 62 public void setShipping(boolean shipping) { 63 this.shipping = shipping; 64 } 65 66 public String getShippingType() { 67 return shippingType; 68 } 69 70 public void setShippingType(String shippingType) { 71 this.shippingType = shippingType; 72 } 73 74 76 79 public double getAmount() { 80 return price * itemCount; 81 } 82 83 86 public double getDiscountRate() { 87 double discount = 0.02; 88 if ("A".equals(category)) { 89 if (itemCount >= 100) { 90 discount = 0.1; 91 } 92 } else if ("B".equals(category)) { 93 if (itemCount >= 200) { 94 discount = 0.2; 95 } 96 } 97 return discount; 98 } 99 100 103 public double getSavings() { 104 return getDiscountRate() * getAmount(); 105 } 106 107 110 public double getDeliveryCost() { 111 double delCost = 0.0; 112 if ("S".equals(shippingType)) { 113 delCost = 10.0; 114 } else if ("E".equals(shippingType)) { 115 delCost = 20.0; 116 } 117 return delCost; 118 } 119 120 123 public double getTotalCost() { 124 return getAmount() + getDeliveryCost() - getSavings(); 125 } 126 127 public String toString() { 128 return new ToStringCreator(this).append("price", price).append( 129 "itemCount", itemCount).toString(); 130 } 131 } | Popular Tags |