Repository navigation
Expand file tree
/
Copy pathOrderRollupApp.java
More file actions
48 lines (40 loc) · 1.56 KB
/
Copy pathOrderRollupApp.java
File metadata and controls
48 lines (40 loc) · 1.56 KB
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
41
42
43
44
45
46
47
48
package dev.trly.java.example.primitive.wrappers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class OrderRollupApp {
private static final Logger LOGGER = LoggerFactory.getLogger(OrderRollupApp.class);
private OrderRollupApp() {
}
public static void main(String[] args) {
final Integer[] boxCounts = {
new Integer(4),
new Integer(7),
new Integer(3),
new Integer(5)
};
final Long[] orderValues = {
new Long(1299L),
new Long(2450L),
new Long(875L),
new Long(1625L)
};
int totalBoxes = 0;
long totalCents = 0L;
for (int index = 0; index < boxCounts.length; index++) {
final int boxes = boxCounts[index].intValue();
final long cents = orderValues[index].longValue();
totalBoxes += boxes;
totalCents += cents;
LOGGER.info("Order {}: {} boxes, ${}", index + 1, boxes, String.format("%.2f", cents / 100.0));
}
LOGGER.info("Shipped {} boxes for ${}", totalBoxes, String.format("%.2f", totalCents / 100.0));
}
public static Integer calculatePackingUnits(int boxesPerOrder, int orderCount) {
return new Integer(boxesPerOrder * orderCount);
}
public static Long estimateShippingCents(long baseCents, int boxCount) {
final Long perBoxCents = new Long(baseCents);
final Long totalCents = new Long(perBoxCents.longValue() * boxCount);
return new Long(totalCents.longValue());
}
}