Skip to content

Commit

Permalink
Added Checkstyle to Share
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent b8e334c commit 098388e
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/main/java/Model/Share.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
package Model;

import java.math.BigDecimal;

/**
* Share class.
*/
public class Share {

private final Stock stock;
private final BigDecimal quantity;
private final BigDecimal purchasePrice;

public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
if (stock == null) {
throw new IllegalArgumentException("Stock cannot be null");
}
if (quantity == null) {
throw new IllegalArgumentException("Quantity cannot be null");
}
if (quantity.compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Quantity must be greater than zero");
}
if (purchasePrice == null) {
throw new IllegalArgumentException("Purchase price cannot be null");
}
if (purchasePrice.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Purchase price cannot be negative");
}

this.stock = stock;
this.quantity = quantity;
this.purchasePrice = purchasePrice;
}
private final Stock stock;
private final BigDecimal quantity;
private final BigDecimal purchasePrice;

public Stock getStock() {
return stock;
/**
* Share method that has stock, quantity and purchaseprice.
*
* @param stock stock name
* @param quantity quantity of stock
* @param purchasePrice price of stock
*/
public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
if (stock == null) {
throw new IllegalArgumentException("Stock cannot be null");
}
if (quantity == null) {
throw new IllegalArgumentException("Quantity cannot be null");
}
if (quantity.compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Quantity must be greater than zero");
}

public BigDecimal getQuantity() {
return quantity;
if (purchasePrice == null) {
throw new IllegalArgumentException("Purchase price cannot be null");
}

public BigDecimal getPurchasePrice() {
return purchasePrice;
if (purchasePrice.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Purchase price cannot be negative");
}

this.stock = stock;
this.quantity = quantity;
this.purchasePrice = purchasePrice;
}

public Stock getStock() {
return stock;
}

public BigDecimal getQuantity() {
return quantity;
}

public BigDecimal getPurchasePrice() {
return purchasePrice;
}

}

0 comments on commit 098388e

Please sign in to comment.