Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.math.BigDecimal;

public class OtherProduct extends Product {

public OtherProduct(String name, BigDecimal price) {
super(name, price, new BigDecimal("0.23"));
}
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/pl/edu/agh/mwo/invoice/product/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,41 @@ public abstract class Product {

private final BigDecimal taxPercent;


protected Product(String name, BigDecimal price, BigDecimal tax) {

if(name == null || name.isBlank()) {
throw new IllegalArgumentException("Product name cannot be null");
}
this.name = name;

if(price == null) {
throw new IllegalArgumentException("Price cannot be null");
}
this.price = price;

if(tax == null|| price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Tax percent cannot be null");
}
this.taxPercent = tax;
}


public String getName() {
return null;
return this.name;
}

public BigDecimal getPrice() {
return null;
return this.price;
}

public BigDecimal getTaxPercent() {
return null;
return this.taxPercent;
}

public BigDecimal getPriceWithTax() {
return null;
BigDecimal result = this.price.multiply(this.taxPercent);
return (BigDecimal)price.add(result);

}
}