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        private String company;
012        private CountingStockImpl csi_shoppingBasket;
013    
014        /**
015         * Creates a new UCustomer.
016         * @param userName the customer's ID.
017         */
018        public UCustomer(String userName){
019            super(userName);
020            csi_shoppingBasket = new CountingStockImpl(userName, SMarket.getArticleCatalog());
021        }
022    
023        /**
024         * Sets the customer's company.
025         * @param company the company to be set.
026         */
027        public void setCompany(String company) {
028            this.company = company;
029        }
030    
031        /**
032         * Gets the customer's company.
033         * @return the company.
034         */
035        public String getCompany() {
036            return company;
037        }
038    
039        /**
040         * Gets the customer's shopping basket.
041         * @return the shopping basket.
042         */
043        public CountingStockImpl getShoppingBasket() {
044            return csi_shoppingBasket;
045        }
046    
047        /**
048         * Computes and returns the customer's current discount.<br>
049         * The discount is a value in the range from 0 to 1.
050         * @return the discount.
051         * @see Options
052         */
053        public double getDiscount() {
054            int allowable = Statistics.getAllowableCustomerRevenue(this);
055            int percentValue = SMarket.getOptions().getDiscountValue();
056            //allowable (in cents) / 100 (Euro) / percentValue (how many percent worth) / 100 (range [0..1))
057            double actualDiscount = new Integer(allowable).doubleValue()/(10000 * percentValue);
058            return Math.min(actualDiscount, SMarket.getOptions().getMaxDiscount());
059        }
060    }