forked from fracz/java-invoice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProduct.java
More file actions
41 lines (30 loc) · 862 Bytes
/
Product.java
File metadata and controls
41 lines (30 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pl.edu.agh.mwo.invoice.product;
import java.math.BigDecimal;
public abstract class Product {
private final String name;
private final BigDecimal price;
private final BigDecimal taxPercent;
protected Product(String name, BigDecimal price, BigDecimal tax) {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("Product name cannot be null");
}
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Product cannot be null");
}
this.name = name;
this.price = price;
this.taxPercent = tax;
}
public String getName() {
return name;
}
public BigDecimal getPrice() {
return price;
}
public BigDecimal getTaxPercent() {
return taxPercent;
}
public BigDecimal getPriceWithTax() {
return this.price.add(this.taxPercent.multiply(this.price));
}
}