Skip to content

Commit

Permalink
Feat: Minor changes to formatting
Browse files Browse the repository at this point in the history
Changed the formatting (inline) of various classes to satisfy checkstyle. Also updated the documentation a bit.
  • Loading branch information
tommyah committed Mar 18, 2026
1 parent 915d867 commit 64b386e
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 510 deletions.
11 changes: 7 additions & 4 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Purchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
* <p>Extends {@link Transaction}</p>
*
* */
public class Purchase extends Transaction {
public final class Purchase extends Transaction {

/**
* Constructor.
*
* @param share the {@link Share} object to purchase.
* @param week the week to purchase during.
* @param calculator the {@link TransactionCalculator} object to calculate this purchase.
* @param calculator the {@link TransactionCalculator}
* object to calculate this purchase.
* */
public Purchase(final Share share, final int week, final TransactionCalculator calculator) {
public Purchase(final Share share,
final int week,
final TransactionCalculator calculator) {
super(share, week, calculator);
}

Expand All @@ -26,6 +29,6 @@ public Purchase(final Share share, final int week, final TransactionCalculator c
* */
@Override
public void commit(final Player player) {
commited = true;
setCommitted(true);
}
}
113 changes: 61 additions & 52 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,75 @@

import java.math.BigDecimal;


/**
* Calculator for purchase transactions.
* <p>
* Uses the share's purchase price and quantity to calculate:
* gross value, commission, tax and total cost.
* </p>
*
* <p>Uses the share's purchase price and quantity to calculate:
* gross value, commission, tax and total cost.</p>
*/
public class PurchaseCalculator implements TransactionCalculator {
public final class PurchaseCalculator implements TransactionCalculator {

/**
* The constant commission rate for purchases.
* */
private static final BigDecimal COMMISSION_RATE
= new BigDecimal("0.005"); // 0.5%

private static final BigDecimal COMMISSION_RATE = new BigDecimal("0.005"); // 0.5%
/**
* The price of the purchase.
* */
private final BigDecimal purchasePrice;

private final BigDecimal purchasePrice;
private final BigDecimal quantity;
/**
* The quantity bought.
* */
private final BigDecimal quantity;

/**
* Creates a new {@code PurchaseCalculator} based on a share.
*
* @param share the share to base calculations on
*/
public PurchaseCalculator(Share share) {
this.purchasePrice = share.getPurchasePrice();
this.quantity = share.getQuantity();
}
/**
* Creates a new {@code PurchaseCalculator} based on a share.
*
* @param share the share to base calculations on
*/
public PurchaseCalculator(final Share share) {
this.purchasePrice = share.getPurchasePrice();
this.quantity = share.getQuantity();
}

/**
* {@inheritDoc}
* Gross value = purchasePrice * quantity.
*/
@Override
public BigDecimal calculateGross() {
return purchasePrice.multiply(quantity);
}
/**
* {@inheritDoc}
* Gross value = purchasePrice * quantity.
*/
@Override
public BigDecimal calculateGross() {
return purchasePrice.multiply(quantity);
}

/**
* {@inheritDoc}
* Commission = 0.5% of gross value.
*/
@Override
public BigDecimal calculateCommission() {
return calculateGross().multiply(COMMISSION_RATE);
}
/**
* {@inheritDoc}
* Commission = 0.5% of gross value.
*/
@Override
public BigDecimal calculateCommission() {
return calculateGross().multiply(COMMISSION_RATE);
}

/**
* {@inheritDoc}
* No tax on purchases.
*/
@Override
public BigDecimal calculateTax() {
return BigDecimal.ZERO;
}
/**
* {@inheritDoc}
* No tax on purchases.
*/
@Override
public BigDecimal calculateTax() {
return BigDecimal.ZERO;
}

/**
* {@inheritDoc}
* Total cost = gross + commission + tax.
*/
@Override
public BigDecimal calculateTotal() {
return calculateGross()
.add(calculateCommission())
.add(calculateTax());
}
/**
* {@inheritDoc}
* Total cost = gross + commission + tax.
*/
@Override
public BigDecimal calculateTotal() {
return calculateGross()
.add(calculateCommission())
.add(calculateTax());
}
}
11 changes: 7 additions & 4 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Sale.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
* <p>Extends {@link Transaction}</p>
*
* */
public class Sale extends Transaction {
public final class Sale extends Transaction {

/**
* Constructor.
*
* @param share the {@link Share} object to purchase.
* @param week the week to purchase during.
* @param calculator the {@link TransactionCalculator} object to calculate this purchase.
* @param calculator the {@link TransactionCalculator}
* object to calculate this purchase.
* */
public Sale(final Share share, final int week, final TransactionCalculator calculator) {
public Sale(final Share share,
final int week,
final TransactionCalculator calculator) {
super(share, week, calculator);
}

Expand All @@ -26,6 +29,6 @@ public Sale(final Share share, final int week, final TransactionCalculator calcu
* */
@Override
public void commit(final Player player) {
commited = true;
setCommitted(true);
}
}
145 changes: 82 additions & 63 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/SaleCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,94 @@

/**
* Calculator for sale transactions.
* <p>
* Calculates gross value, commission, tax and total sale value
* based on the share's purchase price, current sales price and quantity.
* </p>
*
* <p>Calculates gross value, commission, tax and total sale value
* based on the share's purchase price, current sales price and quantity.</p>
*/
public class SaleCalculator implements TransactionCalculator {
public final class SaleCalculator implements TransactionCalculator {

private static final BigDecimal COMMISSION_RATE = new BigDecimal("0.01"); // 1%
private static final BigDecimal TAX_RATE = new BigDecimal("0.30"); // 30%
/**
* The constant commission rate for sales.
* */
private static final BigDecimal COMMISSION_RATE =
new BigDecimal("0.01"); // 1%

private final BigDecimal purchasePrice;
private final BigDecimal salesPrice;
private final BigDecimal quantity;
/**
* The constant tax rates for sales.
* */
private static final BigDecimal TAX_RATE =
new BigDecimal("0.30"); // 30%

/**
* Creates a new {@code SaleCalculator} based on a share.
*
* @param share the share to base calculations on
*/
public SaleCalculator(Share share) {
this.purchasePrice = share.getPurchasePrice();
this.salesPrice = share.getStock().getSalesPrice();
this.quantity = share.getQuantity();
}
/**
* The purchase price of the share.
* */
private final BigDecimal purchasePrice;

/**
* {@inheritDoc}
* Gross value = salesPrice * quantity.
*/
@Override
public BigDecimal calculateGross() {
return salesPrice.multiply(quantity);
}
/**
* The sale price of the share.
* */
private final BigDecimal salesPrice;

/**
* {@inheritDoc}
* Commission = 1% of gross value.
*/
@Override
public BigDecimal calculateCommission() {
return calculateGross().multiply(COMMISSION_RATE);
}
/**
* The quantity the share represents.
* */
private final BigDecimal quantity;

/**
* {@inheritDoc}
* Tax = 30% of profit.
* Profit = gross - commission - (purchasePrice * quantity).
* If profit is negative or zero, tax is zero.
*/
@Override
public BigDecimal calculateTax() {
BigDecimal purchaseCost = purchasePrice.multiply(quantity);
BigDecimal profit = calculateGross()
.subtract(calculateCommission())
.subtract(purchaseCost);
/**
* Creates a new {@code SaleCalculator} based on a share.
*
* @param share the share to base calculations on
*/
public SaleCalculator(final Share share) {
this.purchasePrice = share.getPurchasePrice();
this.salesPrice = share.getStock().getSalesPrice();
this.quantity = share.getQuantity();
}

return profit.signum() > 0
? profit.multiply(TAX_RATE)
: BigDecimal.ZERO;
}
/**
* {@inheritDoc}
* Gross value = salesPrice * quantity.
*/
@Override
public BigDecimal calculateGross() {
return salesPrice.multiply(quantity);
}

/**
* {@inheritDoc}
* Total value = gross - commission - tax.
*/
@Override
public BigDecimal calculateTotal() {
return calculateGross()
.subtract(calculateCommission())
.subtract(calculateTax());
}
}
/**
* {@inheritDoc}
* Commission = 1% of gross value.
*/
@Override
public BigDecimal calculateCommission() {
return calculateGross().multiply(COMMISSION_RATE);
}

/**
* {@inheritDoc}
* Tax = 30% of profit.
* Profit = gross - commission - (purchasePrice * quantity).
* If profit is negative or zero, tax is zero.
*/
@Override
public BigDecimal calculateTax() {
BigDecimal purchaseCost = purchasePrice.multiply(quantity);
BigDecimal profit = calculateGross()
.subtract(calculateCommission())
.subtract(purchaseCost);

return profit.signum() > 0
? profit.multiply(TAX_RATE)
: BigDecimal.ZERO;
}

/**
* {@inheritDoc}
* Total value = gross - commission - tax.
*/
@Override
public BigDecimal calculateTotal() {
return calculateGross()
.subtract(calculateCommission())
.subtract(calculateTax());
}
}
Loading

0 comments on commit 64b386e

Please sign in to comment.