diff --git a/materials/2024-2025/11a/MyDate/.gitignore b/materials/2024-2025/11a/MyDate/.gitignore new file mode 100644 index 00000000..f68d1099 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/.gitignore b/materials/2024-2025/11a/MyDate/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/materials/2024-2025/11a/MyDate/.idea/codeStyles/Project.xml b/materials/2024-2025/11a/MyDate/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/codeStyles/codeStyleConfig.xml b/materials/2024-2025/11a/MyDate/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/misc.xml b/materials/2024-2025/11a/MyDate/.idea/misc.xml new file mode 100644 index 00000000..6f29fee2 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/modules.xml b/materials/2024-2025/11a/MyDate/.idea/modules.xml new file mode 100644 index 00000000..630a632a --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/uiDesigner.xml b/materials/2024-2025/11a/MyDate/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/.idea/vcs.xml b/materials/2024-2025/11a/MyDate/.idea/vcs.xml new file mode 100644 index 00000000..4fce1d86 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/Amazon.de - Order 304-3403052-6009944.pdf b/materials/2024-2025/11a/MyDate/Amazon.de - Order 304-3403052-6009944.pdf new file mode 100644 index 00000000..1770f168 Binary files /dev/null and b/materials/2024-2025/11a/MyDate/Amazon.de - Order 304-3403052-6009944.pdf differ diff --git a/materials/2024-2025/11a/MyDate/MyDate.iml b/materials/2024-2025/11a/MyDate/MyDate.iml new file mode 100644 index 00000000..c90834f2 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/MyDate.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11a/MyDate/myJar.jar b/materials/2024-2025/11a/MyDate/myJar.jar new file mode 100644 index 00000000..06bc5dcd Binary files /dev/null and b/materials/2024-2025/11a/MyDate/myJar.jar differ diff --git a/materials/2024-2025/11a/MyDate/src/Order.java b/materials/2024-2025/11a/MyDate/src/Order.java index 7a945ed3..768ba30f 100644 --- a/materials/2024-2025/11a/MyDate/src/Order.java +++ b/materials/2024-2025/11a/MyDate/src/Order.java @@ -1,4 +1,34 @@ -package PACKAGE_NAME; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class Order { + private List products; + + public Order(List products) { + this.products = products; + } + + public Order() { + this.products = new ArrayList<>(); + } + + public void addProducts(Product... products) { + this.products.addAll(Arrays.asList(products)); + } + private double mySum(double e1, double e2) { + return e1 + e2; + } + public double getTotal() { + return products.stream() + .map(Product::calculatePrice) + .reduce(0d, this::mySum); + } + + @Override + public String toString() { + return "Order{" + + "products=" + products + + '}'; + } } diff --git a/materials/2024-2025/11a/MyDate/src/OrderManagement.java b/materials/2024-2025/11a/MyDate/src/OrderManagement.java new file mode 100644 index 00000000..41eca32f --- /dev/null +++ b/materials/2024-2025/11a/MyDate/src/OrderManagement.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +public class OrderManagement { + public static void main(String[] args) + { + Scanner scanner = new Scanner(System.in); + + Order order = new Order(); + for (String productString : args) { + String[] product = productString.split(","); + Product product1 = new Product(product[0], Double.parseDouble(product[1]), Integer.parseInt(product[2])); + order.addProducts(product1); + } + int i = scanner.nextInt(16); + scanner.skip(); + System.out.println(i); + System.out.println(order); + System.out.printf("Total: %.1f ", order.getTotal()); + } + + +} diff --git a/materials/2024-2025/11a/MyDate/src/Product.java b/materials/2024-2025/11a/MyDate/src/Product.java index 44f80c61..0527e6d3 100644 --- a/materials/2024-2025/11a/MyDate/src/Product.java +++ b/materials/2024-2025/11a/MyDate/src/Product.java @@ -1,4 +1,23 @@ -package PACKAGE_NAME; - public class Product { + private String name; + private double price; + private int quantity; + + public Product(String name, double price, int quantity) { + this.name = name; + this.price = price; + this.quantity = quantity; + } + + public double calculatePrice() { + return price * quantity; + } + + @Override + public String toString() { + return "Product{" + + "name='" + name + '\'' + + ", price=" + calculatePrice() + + '}'; + } } diff --git a/materials/2024-2025/11a/MyDate/task.md b/materials/2024-2025/11a/MyDate/task.md new file mode 100644 index 00000000..cdf86f97 --- /dev/null +++ b/materials/2024-2025/11a/MyDate/task.md @@ -0,0 +1,43 @@ + + +## Задача: Система за управление на поръчки + +Създайте програма, която управлява поръчки в малък онлайн магазин. Всяка поръчка съдържа информация за поръчани продукти, тяхната цена и количество. + +### Условие + +1. **Клас Product**: Създайте клас `Product`, който съдържа: + - Поле `name` за името на продукта. + - Поле `price` за цената на продукта (от тип `double`). + - Поле `quantity` за количеството (бройките) на продукта в поръчката. + - Метод `toString()`, който връща форматиран текст с информация за продукта във вида: `"Product: [име], Price: [цена], Quantity: [количество]"`. + +2. **Клас Order**: Създайте клас `Order`, който има: + - Поле `products`, което съдържа списък от продукти (може да използвате `ArrayList`). + - Метод `addProducts(Product... products)`, който добавя един или повече продукти към поръчката с помощта на varargs. + - Метод `calculateTotal()`, който пресмята общата стойност на поръчката. + - Метод `toString()`, който връща всички продукти в поръчката и общата сума на поръчката. + +3. **Главен клас (OrderManagement)**: + - Чете аргументи от командния ред като продукти с формат: име на продукт, цена и количество, разделени със запетая. Например: + ```shell + java OrderManagement "Apple,1.2,3" "Banana,0.8,5" + ``` + - Създава обекти `Product` от тези аргументи и ги добавя към поръчка. + - Извежда информацията за поръчката, като използва `System.out.printf()` за форматиране на общата стойност до 2 знака след десетичната запетая. + +### Примерен Изход + +Ако стартираме програмата така: +```shell +java OrderManagement "Apple,1.2,3" "Banana,0.8,5" +``` + +Примерен изход може да бъде: +``` +Product: Apple, Price: 1.2, Quantity: 3 +Product: Banana, Price: 0.8, Quantity: 5 +Total Order Price: 5.60 +``` + +---