diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..39f2aec --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..df359e1 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..5ac9cfa --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/lab-java-maven.iml b/.idea/lab-java-maven.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-maven.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2fe1a4e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b361d37 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/order-data.iml b/order-data.iml new file mode 100644 index 0000000..46b8407 --- /dev/null +++ b/order-data.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solution-lab-2.02-maven/order-data/pom.xml b/solution-lab-2.02-maven/order-data/pom.xml new file mode 100644 index 0000000..3b7b36b --- /dev/null +++ b/solution-lab-2.02-maven/order-data/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + org.example + solution-lab-2.02-maven + 1.0-SNAPSHOT + + + + order-data + + + 17 + 17 + UTF-8 + + + + + com.google.code.gson + gson + 2.13.1 + compile + + + + \ No newline at end of file diff --git a/solution-lab-2.02-maven/order-data/src/main/java/org/example/Main.java b/solution-lab-2.02-maven/order-data/src/main/java/org/example/Main.java new file mode 100644 index 0000000..ef56760 --- /dev/null +++ b/solution-lab-2.02-maven/order-data/src/main/java/org/example/Main.java @@ -0,0 +1,7 @@ +package org.example; + +public class Main { + public static void main(String[] args) { + + } +} \ No newline at end of file diff --git a/solution-lab-2.02-maven/order-data/src/main/java/org/example/Order.java b/solution-lab-2.02-maven/order-data/src/main/java/org/example/Order.java new file mode 100644 index 0000000..e57f4da --- /dev/null +++ b/solution-lab-2.02-maven/order-data/src/main/java/org/example/Order.java @@ -0,0 +1,60 @@ +package org.example; + +import java.util.List; + +public class Order { + private int orderId; + private String customer; + private List items; + private double total; + + public Order(int orderId, String customer, List items) { + this.orderId = orderId; + this.customer = customer; + this.items = items; + } + + public int getOrderId() { + return orderId; + } + + public String getCustomer() { + return customer; + } + + public List 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 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"; + } + +} diff --git a/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderItem.java b/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderItem.java new file mode 100644 index 0000000..cc9a301 --- /dev/null +++ b/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderItem.java @@ -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; + } +} diff --git a/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderProcessor.java b/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderProcessor.java new file mode 100644 index 0000000..fe5c4fe --- /dev/null +++ b/solution-lab-2.02-maven/order-data/src/main/java/org/example/OrderProcessor.java @@ -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 orders = Arrays.asList(ordersArray); + orders.forEach(System.out::println); + } +} diff --git a/solution-lab-2.02-maven/order-data/target/classes/org/example/Main.class b/solution-lab-2.02-maven/order-data/target/classes/org/example/Main.class new file mode 100644 index 0000000..3b267cc Binary files /dev/null and b/solution-lab-2.02-maven/order-data/target/classes/org/example/Main.class differ diff --git a/solution-lab-2.02-maven/order-data/target/classes/org/example/Order.class b/solution-lab-2.02-maven/order-data/target/classes/org/example/Order.class new file mode 100644 index 0000000..d19e78b Binary files /dev/null and b/solution-lab-2.02-maven/order-data/target/classes/org/example/Order.class differ diff --git a/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderItem.class b/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderItem.class new file mode 100644 index 0000000..88b4283 Binary files /dev/null and b/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderItem.class differ diff --git a/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderProcessor.class b/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderProcessor.class new file mode 100644 index 0000000..e659ee1 Binary files /dev/null and b/solution-lab-2.02-maven/order-data/target/classes/org/example/OrderProcessor.class differ diff --git a/solution-lab-2.02-maven/order-logic/pom.xml b/solution-lab-2.02-maven/order-logic/pom.xml new file mode 100644 index 0000000..6d68b94 --- /dev/null +++ b/solution-lab-2.02-maven/order-logic/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + org.example + solution-lab-2.02-maven + 1.0-SNAPSHOT + + + order-logic + + + 17 + 17 + UTF-8 + + + + org.example + order-data + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/solution-lab-2.02-maven/order-logic/src/main/java/org/example/Main.java b/solution-lab-2.02-maven/order-logic/src/main/java/org/example/Main.java new file mode 100644 index 0000000..ecfd5a9 --- /dev/null +++ b/solution-lab-2.02-maven/order-logic/src/main/java/org/example/Main.java @@ -0,0 +1,9 @@ +package org.example; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + + } +} \ No newline at end of file diff --git a/solution-lab-2.02-maven/order-logic/src/main/java/org/example/OrderCalculator.java b/solution-lab-2.02-maven/order-logic/src/main/java/org/example/OrderCalculator.java new file mode 100644 index 0000000..a04c1ac --- /dev/null +++ b/solution-lab-2.02-maven/order-logic/src/main/java/org/example/OrderCalculator.java @@ -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 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 orders){ + double sum=0; + for(Order order:orders){ + sum+=order.getTotal(); + } + return sum; + } + public static void filteringHighValueOrders(List orders,double minValue ){ + for(Order order:orders){ + if(order.getTotal()>minValue){ + System.out.println("Id:"+order.getOrderId() + +"\nCustomer:"+order.getCustomer() + +"\nTotal:"+order.getTotal()); + } + } + } +} diff --git a/solution-lab-2.02-maven/order-logic/target/classes/org/example/Main.class b/solution-lab-2.02-maven/order-logic/target/classes/org/example/Main.class new file mode 100644 index 0000000..8e23230 Binary files /dev/null and b/solution-lab-2.02-maven/order-logic/target/classes/org/example/Main.class differ diff --git a/solution-lab-2.02-maven/order-logic/target/classes/org/example/OrderCalculator.class b/solution-lab-2.02-maven/order-logic/target/classes/org/example/OrderCalculator.class new file mode 100644 index 0000000..7cc05b8 Binary files /dev/null and b/solution-lab-2.02-maven/order-logic/target/classes/org/example/OrderCalculator.class differ diff --git a/solution-lab-2.02-maven/pom.xml b/solution-lab-2.02-maven/pom.xml new file mode 100644 index 0000000..29eecfe --- /dev/null +++ b/solution-lab-2.02-maven/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + org.example + solution-lab-2.02-maven + 1.0-SNAPSHOT + pom + + + 17 + 17 + UTF-8 + + + + + org.slf4j + slf4j-api + 2.0.17 + compile + + + + + central + Maven Central Repository + https://repo.maven.apache.org/maven2 + + true + + + false + + + + + + + central + Maven Central Repository + https://repo.maven.apache.org/maven2 + + true + + + false + + + + + order-data + order-logic + + + \ No newline at end of file diff --git a/solution-lab-2.02-maven/src/main/java/org/example/Main.java b/solution-lab-2.02-maven/src/main/java/org/example/Main.java new file mode 100644 index 0000000..d184ce5 --- /dev/null +++ b/solution-lab-2.02-maven/src/main/java/org/example/Main.java @@ -0,0 +1,8 @@ +package org.example; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + } +} \ No newline at end of file