Skip to content

Commit 9c189ce

Browse files
committed
feat:Lesson_14 solutions implemented for Tommy Tran
1 parent 2fbb684 commit 9c189ce

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/EcommerceSystem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public void addProduct(String productId, String name) {
1919

2020
public String placeOrder(String productId, int quantity) {
2121
Product product = products.get(productId);
22+
if (product == null) {
23+
throw new ProductNotFoundException("Product with ID " + productId + " not found");
24+
}
2225
String orderId = UUID.randomUUID().toString();
2326
orders.put(orderId, new Order(orderId, product, quantity));
2427
return orderId;
@@ -30,6 +33,9 @@ public void cancelOrder(String orderId) {
3033

3134
public String checkOrderStatus(String orderId) {
3235
Order order = orders.get(orderId);
36+
if (order == null) {
37+
throw new OrderNotFoundException("Order with ID " + orderId + " not found");
38+
}
3339
return "Order ID: "
3440
+ orderId
3541
+ ", Product: "

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/OrderNotFoundException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55

66
package com.codedifferently.lesson14.ecommerce;
77

8-
class OrderNotFoundException {}
8+
public class OrderNotFoundException extends RuntimeException {
9+
public OrderNotFoundException(String message) {
10+
super(message);
11+
}
12+
}

lesson_14/exceptions/exceptions_app/src/main/java/com/codedifferently/lesson14/ecommerce/ProductNotFoundException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55

66
package com.codedifferently.lesson14.ecommerce;
77

8-
class ProductNotFoundException {}
8+
public class ProductNotFoundException extends RuntimeException {
9+
public ProductNotFoundException(String message) {
10+
super(message);
11+
}
12+
}

0 commit comments

Comments
 (0)