import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; /** * Sample implementation of a pricing agent. * * Chooses the mean of the the competitor prices of the last period as its own * price. * */ public class SimpleAgent implements ShopAgentInterface { // list to store the prices of the competitors List allPrices; // constants static double p_uvp = 15.0; static double p_max = 1.5 * p_uvp; static double p_ek = 10.0; /** * Constructor. * * Instantiates the price list. */ public SimpleAgent() { allPrices = new ArrayList(); } public double getPrice() throws Exception { // our price double ownPrice; // calculate the price; if first period choose p_uvp if (allPrices.size() == 0) { ownPrice = p_uvp; } else { ownPrice = getMeanPrice(); } // map to p_max or p_min if needed if (ownPrice >= p_max) ownPrice = p_max - 0.5; if (ownPrice <= p_ek) ownPrice = 10.5; // round the price according to the requirements BigDecimal bd = new BigDecimal(ownPrice); ownPrice = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); return ownPrice; } public void parseSales(int sales) throws Exception { } public void parsePrices(List prices) throws Exception { allPrices = prices; } /** * Get the mean price. * * @return mean of allPrices */ private double getMeanPrice() { double s = 0.0; for (int i = 0; i < allPrices.size(); i++) { s = s + allPrices.get(i); } s = s / allPrices.size(); return s; } }