1
1
package pl .edu .agh .mwo .invoice ;
2
2
3
3
import java .math .BigDecimal ;
4
- import java .time .LocalDate ;
5
4
import java .util .ArrayList ;
6
5
import java .util .Collection ;
7
6
8
7
import pl .edu .agh .mwo .invoice .product .Product ;
9
8
10
-
11
9
public class Invoice {
12
10
private Collection <Product > products ;
13
11
private BigDecimal subTotal ;
@@ -16,67 +14,66 @@ public class Invoice {
16
14
17
15
18
16
Invoice () {
19
- netValue = new BigDecimal ("0" );
17
+ subTotal = new BigDecimal ("0" );
20
18
total = new BigDecimal ("0" );
21
19
tax = new BigDecimal ("0" );
22
20
products = new ArrayList <Product >();
23
21
24
22
}
25
23
26
-
27
- public void addProduct (Product product ) {
28
- products .add (Product );
24
+ public void addProduct (Product product ) {
25
+ products .add (product );
29
26
update ();
30
27
}
31
28
32
29
public void addProduct (Product product , Integer quantity ) {
33
30
if (quantity <= 0 ) {
34
- throw new IllegalArgumentException ();
31
+ throw new IllegalArgumentException ();
35
32
}
36
- for (int i =0 ; i < quantity ; i ++) {
37
- products .add (product );
38
- }
39
- update ();
40
- }
41
- public void setSubTotal () {
42
-
43
- subTotal = BigDecimal .ZERO ;
44
- for (Product product : products ) {
45
- subTotal = subTotal .add (product .getPrice ());
33
+ for (int i = 0 ; i < quantity ; i ++) {
34
+ products .add (product );
46
35
}
36
+ update ();
47
37
}
48
-
49
38
public BigDecimal getSubtotal () {
50
39
return subTotal ;
51
40
}
41
+ public void setSubtotal () {
42
+ subTotal = BigDecimal .ZERO ;
43
+ for (Product product : products ) {
44
+ subTotal = subTotal .add (product .getPrice ());
45
+ }
46
+ }
52
47
53
- public void setTax () {
54
- tax = total .subtract (subTotal );
55
-
56
- }
57
48
public BigDecimal getTax () {
58
49
return tax ;
59
50
}
51
+
52
+ public void setTax () {
53
+ tax = total .subtract (subTotal );
54
+ }
60
55
61
56
public BigDecimal getTotal () {
62
57
return total ;
63
- }
64
-
58
+ }
65
59
public void setTotal () {
66
-
67
- total = BigDecimal .ZERO ;
68
- for (Product product : products ) {
69
- total = total .add (product .getPriceWithTax ());
60
+ total = BigDecimal .ZERO ;
61
+ for (Product product : products ) {
62
+ total = total .add (product .getPriceWithTax ());
70
63
}
71
64
}
65
+
72
66
public static Invoice create () {
73
- return new Invoice ();
74
- }
75
-
76
- public void update () {
77
- setSubtotal ();
78
- setTotal ();
79
- setTax ();
67
+ return new Invoice ();
68
+ }
69
+
70
+ public void update () {
71
+ setSubtotal ();
72
+ setTotal ();
73
+ setTax ();
80
74
}
75
+
76
+
77
+
81
78
}
82
79
0 commit comments