diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java index 9c5796a..b73f634 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java @@ -208,7 +208,9 @@ public Transaction sell(final Share share, final Player player) * * @throws IllegalArgumentException if any parameter is null, or if player does not have enough shares. * */ - public List sell(BigDecimal amount, final String stockSymbol, final Player player) + public List sell(BigDecimal amount, + final String stockSymbol, + final Player player) throws IllegalArgumentException { if (amount == null || player == null || !Validator.NOT_EMPTY.isValid(stockSymbol)) { throw new IllegalArgumentException("Invalid sell!"); @@ -253,7 +255,8 @@ public void advance() { for (Stock stock : stockMap.values()) { BigDecimal currentPrice = stock.getSalesPrice(); - double change = (random.nextDouble() * 0.10) - 0.05; + double change = ((random.nextDouble() * 0.10) - 0.05) + stock.getFortune(); + stock.setFortune(0); BigDecimal factor = BigDecimal.valueOf(1 + change); BigDecimal newPrice = currentPrice.multiply(factor); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Stock.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Stock.java index 11a444e..1ca9664 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Stock.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Stock.java @@ -26,6 +26,14 @@ public final class Stock { * */ private final List prices = new ArrayList<>(); + /** + * Value indicating this stocks fortune. + * + *

Higher fortune yields a higher + * increase when stock market changes price.

+ * */ + private double fortune; + /** * Creates a new {@code Stock} with an initial sales price. * @@ -42,10 +50,29 @@ public Stock(final String symbol, } else { this.symbol = symbol; this.company = company; + this.fortune = 0; prices.add(salesPrice); } } + /** + * Setter method for fortune. + * + * @param newFortune the new value to set this stocks' fortune. + * */ + public void setFortune(final double newFortune) { + fortune = newFortune; + } + + /** + * Getter method for fortune. + * + * @return fortune. + * */ + public double getFortune() { + return fortune; + } + /** * Returns the stock symbol. *