File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
src/main/java/pl/edu/agh/mwo/invoice/product Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ public abstract class Product {
1010 private final BigDecimal taxPercent ;
1111
1212 protected Product (String name , BigDecimal price , BigDecimal tax ) {
13+ if (name == null || name .isEmpty ()) {
14+ throw new IllegalArgumentException ("Product name cannot be null and cannot be empty" );
15+ }
16+ if (price == null || price .signum () == -1 ) {
17+ throw new IllegalArgumentException ("Price cannot be negative and null." );
18+ }
1319 this .name = name ;
1420 this .price = price ;
1521 this .taxPercent = tax ;
@@ -20,14 +26,14 @@ public String getName() {
2026 }
2127
2228 public BigDecimal getPrice () {
23- return null ;
29+ return price ;
2430 }
2531
2632 public BigDecimal getTaxPercent () {
27- return null ;
33+ return taxPercent ;
2834 }
2935
3036 public BigDecimal getPriceWithTax () {
31- return null ;
37+ return this . price . multiply ( this . taxPercent ). add ( this . price ) ;
3238 }
3339}
You can’t perform that action at this time.
0 commit comments