Skip to content
Open
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
30 changes: 30 additions & 0 deletions solution-lab-2.02/order-data/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ironhack</groupId>
<artifactId>solution-lab-2.02</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>order-data</artifactId>

<properties>
<maven.compiler.source>24</maven.compiler.source>
<maven.compiler.target>24</maven.compiler.target>
<java.version>24</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Gson for JSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>

</project>
58 changes: 58 additions & 0 deletions solution-lab-2.02/order-data/src/main/java/org/ironhack/Order.java
Original file line number Diff line number Diff line change
@@ -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<OrderItem> items;

public Order(int orderId, String customer, double total, List<OrderItem> 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<OrderItem> getItems() {
return items;
}

public void setItems(List<OrderItem> items) {
this.items = items;
}

@Override
public String toString() {
return "Order ID: " + orderId +
"\nCustomer: " + customer +
"\nItems: " + items +
"\nTotal: " + total;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);



}

}
29 changes: 29 additions & 0 deletions solution-lab-2.02/order-logic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ironhack</groupId>
<artifactId>solution-lab-2.02</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>order-logic</artifactId>

<properties>
<maven.compiler.source>24</maven.compiler.source>
<maven.compiler.target>24</maven.compiler.target>
<java.version>24</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.ironhack</groupId>
<artifactId>order-data</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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<OrderItem> orderItems) {
return orderItems.stream()
.mapToDouble(OrderItem::getPrice)
.min().orElse(0);
}

}
47 changes: 47 additions & 0 deletions solution-lab-2.02/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.ironhack</groupId>
<artifactId>solution-lab-2.02</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>order-data</module>
<module>order-logic</module>
</modules>

<properties>
<maven.compiler.source>24</maven.compiler.source>
<maven.compiler.target>24</maven.compiler.target>
<java.version>24</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>

</project>