Skip to content

Commit

Permalink
Fixed merging issue, code now runs
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent 71c1575 commit a655a3f
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/main/java/Model/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public List<Stock> findStocks(String searchTerm) {
}

return result;
}
}

public Transaction buy(String symbol, BigDecimal quantity, Player player) {
if (symbol == null || symbol.isBlank()) {
Expand Down Expand Up @@ -133,23 +133,16 @@ public Transaction sell(Share share, Player player) {

public Transaction sell(Share originalShare, BigDecimal sellQuantity, Player player) {
if (originalShare == null || sellQuantity == null) {
return null;
}

// Kan ikke selge mer enn man eier
if (sellQuantity.compareTo(originalShare.getQuantity()) > 0) {
return null;
}

if (share == null) {
throw new IllegalArgumentException("Share cannot be null");
throw new IllegalArgumentException("Share and quantity cannot be null");
}
if (player == null) {
throw new IllegalArgumentException("Player cannot be null");
}

Sale sale = new Sale(share, this.week);
sale.commit(player);
// Kan ikke selge mer enn man eier
if (sellQuantity.compareTo(originalShare.getQuantity()) > 0) {
throw new IllegalArgumentException("Cannot sell more shares than owned");
}


Share shareToSell;
Expand Down Expand Up @@ -182,7 +175,7 @@ public Transaction sell(Share originalShare, BigDecimal sellQuantity, Player pla
shareToSell = originalShare;
}

// Salgstransaksjon via fabrikken
// Salgstransaksjon
Transaction sale = TransactionFactory.createSale(shareToSell, this.week);

sale.commit(player);
Expand Down

0 comments on commit a655a3f

Please sign in to comment.