Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ repositories {
mavenCentral()
}

dependencies {
implementation 'org.slf4j:slf4j-api:2.0.16'
runtimeOnly 'org.slf4j:slf4j-simple:2.0.16'
}

application {
mainClass = 'dev.trly.java.example.primitive.wrappers.OrderRollupApp'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package dev.trly.java.example.primitive.wrappers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class InventoryAuditApp {
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryAuditApp.class);

private InventoryAuditApp() {
}

Expand Down Expand Up @@ -34,15 +39,15 @@ public static void main(String[] args) {
totalValue += price;
availableCount++;
}
System.out.printf(
"Item %d: $%.2f, grade %c, %s%n",
LOGGER.info(
"Item {}: ${}, grade {}, {}",
index + 1,
price,
grade,
String.format("%.2f", price),
String.format("%c", grade),
available ? "in stock" : "out of stock");
}

System.out.printf("Available items: %d worth $%.2f%n", availableCount, totalValue);
LOGGER.info("Available items: {} worth ${}", availableCount, String.format("%.2f", totalValue));
}

public static Double calculateAverageValue(double totalValue, int itemCount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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() {
}

Expand All @@ -25,10 +30,10 @@ public static void main(String[] args) {
final long cents = orderValues[index].longValue();
totalBoxes += boxes;
totalCents += cents;
System.out.printf("Order %d: %d boxes, $%.2f%n", index + 1, boxes, cents / 100.0);
LOGGER.info("Order {}: {} boxes, ${}", index + 1, boxes, String.format("%.2f", cents / 100.0));
}

System.out.printf("Shipped %d boxes for $%.2f%n", totalBoxes, totalCents / 100.0);
LOGGER.info("Shipped {} boxes for ${}", totalBoxes, String.format("%.2f", totalCents / 100.0));
}

public static Integer calculatePackingUnits(int boxesPerOrder, int orderCount) {
Expand Down
Loading