001    package market;
002    
003    import market.statistics.Statistics;
004    import data.ooimpl.CountingStockImpl;
005    
006    /**
007     * This class implements the customers of the market.
008     */
009    public class UCustomer extends UPerson {
010    
011        /**
012             * ID for serialization.
013             */
014            private static final long serialVersionUID = 8256899920218903123L;
015            
016            private String company;
017        private CountingStockImpl csi_shoppingBasket;
018    
019        /**
020         * Creates a new UCustomer.
021         * @param userName the customer's ID.
022         */
023        public UCustomer(String userName){
024            super(userName);
025            csi_shoppingBasket = new CountingStockImpl(userName, SMarket.getArticleCatalog());
026        }
027    
028        /**
029         * Sets the customer's company.
030         * @param company the company to be set.
031         */
032        public void setCompany(String company) {
033            this.company = company;
034        }
035    
036        /**
037         * Gets the customer's company.
038         * @return the company.
039         */
040        public String getCompany() {
041            return company;
042        }
043    
044        /**
045         * Gets the customer's shopping basket.
046         * @return the shopping basket.
047         */
048        public CountingStockImpl getShoppingBasket() {
049            return csi_shoppingBasket;
050        }
051    
052        /**
053         * Computes and returns the customer's current discount.<br>
054         * The discount is a value in the range from 0 to 1.
055         * @return the discount.
056         * @see Options
057         */
058        public double getDiscount() {
059            int allowable = Statistics.getAllowableCustomerRevenue(this);
060            int percentValue = SMarket.getOptions().getDiscountValue();
061            //allowable (in cents) / 100 (Euro) / percentValue (how many percent worth) / 100 (range [0..1))
062            double actualDiscount = new Integer(allowable).doubleValue()/(10000 * percentValue);
063            return Math.min(actualDiscount, SMarket.getOptions().getMaxDiscount());
064        }
065    }