Skip to content

Fixed merging issue, code now runs #25

Merged
merged 1 commit into from
May 24, 2026
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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