File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed
src/main/java/pl/edu/agh/mwo/invoice/product Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -10,24 +10,34 @@ public abstract class Product {
10
10
private final BigDecimal taxPercent ;
11
11
12
12
protected Product (String name , BigDecimal price , BigDecimal tax ) {
13
- this .name = name ;
13
+ if (name == null || name .equals ("" )) {
14
+ throw new IllegalArgumentException (
15
+ "You cannot create products with null or empty name."
16
+ );
17
+ }
18
+ if (price == null || price .signum () == -1 ) {
19
+ throw new IllegalArgumentException (
20
+ "You cannot create products with null or negative price."
21
+ );
22
+ }
23
+ this .name = name ;
14
24
this .price = price ;
15
25
this .taxPercent = tax ;
16
26
}
17
27
18
28
public String getName () {
19
- return null ;
29
+ return this . name ;
20
30
}
21
31
22
32
public BigDecimal getPrice () {
23
- return null ;
24
- }
33
+ return price ;
34
+ }
25
35
26
- public BigDecimal getTaxPercent () {
27
- return null ;
28
- }
36
+ public BigDecimal getTaxPercent () {
37
+ return taxPercent ;
38
+ }
29
39
30
- public BigDecimal getPriceWithTax () {
31
- return null ;
40
+ public BigDecimal getPriceWithTax () {
41
+ return this . price . multiply ( this . taxPercent ). add ( this . price ) ;
32
42
}
33
43
}
You can’t perform that action at this time.
0 commit comments