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
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Order-logic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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>com.ironhack</groupId>
<artifactId>solution-lab-2.02-maven</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>



<artifactId>Order-logic</artifactId>

<dependencies>
<dependency>
<groupId>com.ironhack</groupId>
<artifactId>order-data</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

</dependencies>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
53 changes: 53 additions & 0 deletions Order-logic/src/main/java/ironhack/OrderCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ironhack;


import java.util.ArrayList;
import java.util.List;

public class OrderCalculator {




public static double calculateTotalPrice(Order order) {
double total = 0;
for (Item item : order.getItems()) {
total += item.getQuantity() * item.getPrice();

}
return total;
}

public static List<Item> filterItemsByPrice(Order order, double price){
List<Item> filteredItems = new ArrayList<>();
for (Item item : order.getItems()) {
if(item.getPrice()==price){
filteredItems.add(item);
}
}
return filteredItems;
}

public static void main(String[] args) {
OrderProcessor orderProcessor = new OrderProcessor();


System.out.println("Total price: " + calculateTotalPrice(orderProcessor.order));
System.out.println("Items with price 10.0: " + filterItemsByPrice(orderProcessor.order, 10.0));
}








}







30 changes: 30 additions & 0 deletions 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>com.ironhack</groupId>
<artifactId>solution-lab-2.02-maven</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>


<artifactId>order-data</artifactId>


<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
73 changes: 73 additions & 0 deletions order-data/src/main/java/ironhack/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ironhack;

public class Item {
private String productId;
private String name;;
private int quantity;
private double price;


public Item(String productId, String name, int quantity, double price) {
if (productId == null) {
throw new IllegalArgumentException("Product ID cannot be null");
}

if (name == null) {
throw new IllegalArgumentException("Name cannot be null");
}

if (quantity < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
}


if (price < 0) {
throw new IllegalArgumentException("Price cannot be negative");
}




this.productId = productId;
this.name = name;
this.quantity = quantity;
this.price = price;

}

public String getName() {
return name;
}



public String getProductId() {
return productId;
}



public int getQuantity() {
return quantity;
}



public double getPrice() {
return price;
}





@Override
public String toString() {
return "Item{" +
"productId='" + productId + '\'' +
", name='" + name + '\'' +
", quantity=" + quantity +
", price=" + price +
'}';
}
}
60 changes: 60 additions & 0 deletions order-data/src/main/java/ironhack/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ironhack;

import java.util.List;

public class Order {
private String orderId;
private String customerId;
private List<Item> items;


public Order(String orderId, String customerId, List<Item> items) {
if (orderId == null) {
throw new IllegalArgumentException("Order ID cannot be null");
}

if (customerId == null) {
throw new IllegalArgumentException("Customer ID cannot be null");
}

if (items == null) {
throw new IllegalArgumentException("Items cannot be null");
}




this.orderId = orderId;
this.customerId = customerId;
this.items = items;

}

public String getOrderId() {
return orderId;
}



public String getCustomerId() {
return customerId;
}



public List<Item> getItems() {
return items;
}




@Override
public String toString() {
return "Order{" +
"orderId='" + orderId + '\'' +
", customerId='" + customerId + '\'' +
", items=" + items +
'}';
}
}
40 changes: 40 additions & 0 deletions order-data/src/main/java/ironhack/OrderProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ironhack;

import com.google.gson.Gson;

public class OrderProcessor {
public static void main(String[] args) {
OrderProcessor processor = new OrderProcessor();
processor.processOrder();
}

Gson gson = new Gson();


String jsonOrder= """
{
"orderId": "12345",
"customerId": "67890",
"items": [
{"productId": "111", "name": "Laptop", "quantity": 2, "price": 10.0},
{"productId": "222", "name": "Camera", "quantity": 1, "price": 20.0}
]
}
""";



Order order = gson.fromJson(jsonOrder, Order.class);

public void processOrder () {
System.out.println("Processing order: " + order.getOrderId());
System.out.println("Customer ID: " + order.getCustomerId());
System.out.println("Items:");
for (Item item : order.getItems()) {
System.out.println("- " + item.getName() + ": " + item.getQuantity() + " x $" + item.getPrice());
}

}


}
Loading