Skip to content

Commit d83f42b

Browse files
committed
Entire class Invoice once again
1 parent 89506bb commit d83f42b

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

Invoice.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package pl.edu.agh.mwo.invoice;
22

33
import java.math.BigDecimal;
4-
import java.time.LocalDate;
54
import java.util.ArrayList;
65
import java.util.Collection;
76

87
import pl.edu.agh.mwo.invoice.product.Product;
98

10-
119
public class Invoice {
1210
private Collection<Product> products;
1311
private BigDecimal subTotal;
@@ -16,67 +14,66 @@ public class Invoice {
1614

1715

1816
Invoice() {
19-
netValue = new BigDecimal("0");
17+
subTotal = new BigDecimal("0");
2018
total = new BigDecimal("0");
2119
tax = new BigDecimal("0");
2220
products = new ArrayList<Product>();
2321

2422
}
2523

26-
27-
public void addProduct(Product product) {
28-
products.add(Product);
24+
public void addProduct(Product product) {
25+
products.add(product);
2926
update();
3027
}
3128

3229
public void addProduct(Product product, Integer quantity) {
3330
if (quantity <= 0) {
34-
throw new IllegalArgumentException();
31+
throw new IllegalArgumentException();
3532
}
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);
4635
}
36+
update();
4737
}
48-
4938
public BigDecimal getSubtotal() {
5039
return subTotal;
5140
}
41+
public void setSubtotal() {
42+
subTotal = BigDecimal.ZERO;
43+
for (Product product : products) {
44+
subTotal = subTotal.add(product.getPrice());
45+
}
46+
}
5247

53-
public void setTax() {
54-
tax = total.subtract(subTotal);
55-
56-
}
5748
public BigDecimal getTax() {
5849
return tax;
5950
}
51+
52+
public void setTax() {
53+
tax = total.subtract(subTotal);
54+
}
6055

6156
public BigDecimal getTotal() {
6257
return total;
63-
}
64-
58+
}
6559
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());
7063
}
7164
}
65+
7266
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();
8074
}
75+
76+
77+
8178
}
8279

0 commit comments

Comments
 (0)