Skip to content

Commit

Permalink
Added Checkstyle to Sale
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent 03e503c commit e2c15cb
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/main/java/Model/Sale.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package Model;

import java.math.BigDecimal;

/**
* Sale class for whenever the player makes a sale.
*/
public class Sale extends Transaction {
public Sale(Share share, int week) {
super(share, week, new SaleCalculator(share));
}
public Sale(Share share, int week) {
super(share, week, new SaleCalculator(share));
}

@Override
public void commit(Player player) {
if (player == null) {
throw new IllegalArgumentException("Player cannot be null");
}
if (isCommitted()) {
throw new IllegalStateException("Sale has already been committed");
}
if (!player.getPortfolio().contains(this.getShare())) {
throw new IllegalStateException(
"Share not found in player's portfolio: " + this.getShare().getStock().getSymbol()
);
}
@Override
public void commit(Player player) {
if (player == null) {
throw new IllegalArgumentException("Player cannot be null");
}
if (isCommitted()) {
throw new IllegalStateException("Sale has already been committed");
}
if (!player.getPortfolio().contains(this.getShare())) {
throw new IllegalStateException(
"Share not found in player's portfolio: " + this.getShare().getStock().getSymbol()
);
}

BigDecimal price = getCalculator().calculateTotal();
BigDecimal price = getCalculator().calculateTotal();

player.addMoney(price);
player.getPortfolio().removeShare(this.getShare());
player.getTransactionArchive().add(this);
player.addMoney(price);
player.getPortfolio().removeShare(this.getShare());
player.getTransactionArchive().add(this);

this.committed = true;
}
this.committed = true;
}
}

0 comments on commit e2c15cb

Please sign in to comment.