diff --git a/solution-lab-2.02/order-data/pom.xml b/solution-lab-2.02/order-data/pom.xml new file mode 100644 index 0000000..8deb268 --- /dev/null +++ b/solution-lab-2.02/order-data/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + org.ironhack + solution-lab-2.02 + 1.0-SNAPSHOT + + + order-data + + + 24 + 24 + 24 + UTF-8 + + + + + + com.google.code.gson + gson + 2.11.0 + + + + \ No newline at end of file diff --git a/solution-lab-2.02/order-data/src/main/java/org/ironhack/Order.java b/solution-lab-2.02/order-data/src/main/java/org/ironhack/Order.java new file mode 100644 index 0000000..9927991 --- /dev/null +++ b/solution-lab-2.02/order-data/src/main/java/org/ironhack/Order.java @@ -0,0 +1,58 @@ +package org.ironhack; + +import java.util.List; + +public class Order { + + private int orderId; + private String customer; + private double total; + private List items; + + public Order(int orderId, String customer, double total, List items) { + this.orderId = orderId; + this.customer = customer; + this.total = total; + this.items = items; + } + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } + + public String getCustomer() { + return customer; + } + + public void setCustomer(String customer) { + this.customer = customer; + } + + public double getTotal() { + return total; + } + + public void setTotal(double total) { + this.total = total; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + @Override + public String toString() { + return "Order ID: " + orderId + + "\nCustomer: " + customer + + "\nItems: " + items + + "\nTotal: " + total; + } +} diff --git a/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderItem.java b/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderItem.java new file mode 100644 index 0000000..5cdd764 --- /dev/null +++ b/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderItem.java @@ -0,0 +1,45 @@ +package org.ironhack; + +public class OrderItem { + private String productName; + private int quantity; + private double price; + + public OrderItem(String productName, int quantity, double price) { + this.productName = productName; + this.quantity = quantity; + this.price = price; + + } + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + @Override + public String toString() { + return "Product: " + productName + + ", Quantity: " + quantity + + ", Price: " + price; + } +} diff --git a/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderProcessor.java b/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderProcessor.java new file mode 100644 index 0000000..ad9f590 --- /dev/null +++ b/solution-lab-2.02/order-data/src/main/java/org/ironhack/OrderProcessor.java @@ -0,0 +1,39 @@ +package org.ironhack; + +import com.google.gson.Gson; + +public class OrderProcessor { + public static void main(String[] args) { + String json = """ + { + "orderId": 1, + "customer": "John Doe", + "items": [ + { + "productName": "Laptop", + "quantity": 1, + "price": 1200.50 + }, + { + "productName": "Mouse", + "quantity": 2, + "price": 25.00 + } + ], + "total": 1250.50 + } + """; + + Gson gson = new Gson(); + + Order order = gson.fromJson(json, Order.class); + + System.out.println("Parsed Order:"); + + System.out.println(order); + + + + } + +} diff --git a/solution-lab-2.02/order-logic/pom.xml b/solution-lab-2.02/order-logic/pom.xml new file mode 100644 index 0000000..85da696 --- /dev/null +++ b/solution-lab-2.02/order-logic/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.ironhack + solution-lab-2.02 + 1.0-SNAPSHOT + + + order-logic + + + 24 + 24 + 24 + UTF-8 + + + + org.ironhack + order-data + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/solution-lab-2.02/order-logic/src/main/java/org/ironhack/OrderCalculator.java b/solution-lab-2.02/order-logic/src/main/java/org/ironhack/OrderCalculator.java new file mode 100644 index 0000000..55222c4 --- /dev/null +++ b/solution-lab-2.02/order-logic/src/main/java/org/ironhack/OrderCalculator.java @@ -0,0 +1,27 @@ +package org.ironhack; +import org.ironhack.Order; + +import java.util.ArrayList; +import java.util.Comparator; + +public class OrderCalculator { + public double calculate(Order order) { + return order.getItems().stream() + .mapToDouble(item -> item.getPrice()*item.getQuantity()) + .sum(); + + } + + public double filterExpensiveItems(Order order) { + return order.getItems().stream() + .mapToDouble(OrderItem::getPrice) + .max().orElse(0); + } + + public double filterCheapItems(ArrayList orderItems) { + return orderItems.stream() + .mapToDouble(OrderItem::getPrice) + .min().orElse(0); + } + +} diff --git a/solution-lab-2.02/pom.xml b/solution-lab-2.02/pom.xml new file mode 100644 index 0000000..f0b39d8 --- /dev/null +++ b/solution-lab-2.02/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + org.ironhack + solution-lab-2.02 + 1.0-SNAPSHOT + pom + + order-data + order-logic + + + + 24 + 24 + 24 + UTF-8 + + + + + + org.slf4j + slf4j-api + 2.0.9 + + + + + + + central + https://repo.maven.apache.org/maven2 + + + + + + central + https://repo.maven.apache.org/maven2 + + + + \ No newline at end of file