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
5 changes: 5 additions & 0 deletions .idea/.gitignore

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

14 changes: 14 additions & 0 deletions .idea/compiler.xml

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

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

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

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

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

9 changes: 9 additions & 0 deletions .idea/lab-java-maven.iml

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

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

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

9 changes: 9 additions & 0 deletions .idea/modules.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.

8 changes: 8 additions & 0 deletions order-data.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$/solution-lab-2.02-maven/order-data" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/solution-lab-2.02-maven/order-data/src/main/java" isTestSource="false" />
</content>
</component>
</module>
30 changes: 30 additions & 0 deletions solution-lab-2.02-maven/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.example</groupId>
<artifactId>solution-lab-2.02-maven</artifactId>
<version>1.0-SNAPSHOT</version>

</parent>

<artifactId>order-data</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Source: https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example;

public class Main {
public static void main(String[] args) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.example;

import java.util.List;

public class Order {
private int orderId;
private String customer;
private List<OrderItem> items;
private double total;

public Order(int orderId, String customer, List<OrderItem> items) {
this.orderId = orderId;
this.customer = customer;
this.items = items;
}

public int getOrderId() {
return orderId;
}

public String getCustomer() {
return customer;
}

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

public double getTotal() {
double sum=0;
for(OrderItem orderItem:items){
sum+=orderItem.getPrice()*orderItem.getQuantity();
}
return sum;
}

public void setOrderId(int orderId) {
this.orderId = orderId;
}

public void setCustomer(String customer) {
this.customer = customer;
}

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

public void setTotal(double total) {
this.total = total;
}
@Override
public String toString() {
return "Order Id: " + orderId +
"\nCustomer: " + customer +
"\nItems: " + items +
"\nTotal: " + getTotal() + "\n";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.example;

import java.util.List;

public class OrderItem {
private String product;
private int quantity;
private double price;

public OrderItem(String product, int quantity, double price) {
this.product = product;
this.quantity = quantity;
this.price = price;
}

public String getProduct() {
return product;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
}

public void setProduct(String product) {
this.product = product;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public void setPrice(double price) {
this.price = price;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.example;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.List;

public class OrderProcessor {
public static void main(String[] args) throws IOException {
String ordersJson = """
[
{
"orderId": 1,
"customer": "Ulvi",
"items": [
{"name": "phone", "quantity": 2, "price": 203.7},
{"name": "jeans", "quantity": 4, "price": 28.3}
]
},
{
"orderId": 2,
"customer": "Esnad",
"items": [
{"name": "phone", "quantity": 1, "price": 203.7},
{"name": "jeans", "quantity": 2, "price": 28.3},
{"name": "hat", "quantity": 2, "price": 13.7}
]
},
{
"orderId": 3,
"customer": "Aysel",
"items": [
{"name": "laptop", "quantity": 1, "price": 899.99},
{"name": "mouse", "quantity": 1, "price": 19.99}
]
}
]
""";
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Order[] ordersArray = gson.fromJson(ordersJson, Order[].class);
List<Order> orders = Arrays.asList(ordersArray);
orders.forEach(System.out::println);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions solution-lab-2.02-maven/order-logic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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.example</groupId>
<artifactId>solution-lab-2.02-maven</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>order-logic</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.example</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,9 @@
package org.example;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.example;


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

public class OrderCalculator {
public static void main(String[] args) {
OrderItem orderItem1=new OrderItem("phone",2,203.7);
OrderItem orderItem2=new OrderItem("jeans",4,28.3);
OrderItem orderItem3=new OrderItem("hat",2,13.7);

Order order1=new Order(1,"Ulvi",List.of(orderItem1,orderItem2));
Order order2=new Order(2,"Esnad",List.of(orderItem1,orderItem2,orderItem3));

List<Order> orders=List.of(order1,order2);
System.out.println("TotalRevenue:"+totalRevenue(orders));

System.out.println("Orders above 500");
filteringHighValueOrders(orders,500);
}

public static double totalRevenue(List<Order> orders){
double sum=0;
for(Order order:orders){
sum+=order.getTotal();
}
return sum;
}
public static void filteringHighValueOrders(List<Order> orders,double minValue ){
for(Order order:orders){
if(order.getTotal()>minValue){
System.out.println("Id:"+order.getOrderId()
+"\nCustomer:"+order.getCustomer()
+"\nTotal:"+order.getTotal());
}
}
}
}
Binary file not shown.
Binary file not shown.
Loading