Skip to content

Commit

Permalink
Legacy classwork
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Jordanov committed Nov 18, 2024
1 parent 9c1801b commit 5faee98
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 3 deletions.
29 changes: 29 additions & 0 deletions materials/2024-2025/11a/MyDate/.gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/.gitignore

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

7 changes: 7 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/codeStyles/Project.xml

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

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

6 changes: 6 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/modules.xml

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

124 changes: 124 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/uiDesigner.xml

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

6 changes: 6 additions & 0 deletions materials/2024-2025/11a/MyDate/.idea/vcs.xml

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

Binary file not shown.
11 changes: 11 additions & 0 deletions materials/2024-2025/11a/MyDate/MyDate.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file added materials/2024-2025/11a/MyDate/myJar.jar
Binary file not shown.
32 changes: 31 additions & 1 deletion materials/2024-2025/11a/MyDate/src/Order.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package PACKAGE_NAME;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Order {
private List<Product> products;

public Order(List<Product> 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 +
'}';
}
}
22 changes: 22 additions & 0 deletions materials/2024-2025/11a/MyDate/src/OrderManagement.java
Original file line number Diff line number Diff line change
@@ -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());
}


}
23 changes: 21 additions & 2 deletions materials/2024-2025/11a/MyDate/src/Product.java
Original file line number Diff line number Diff line change
@@ -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() +
'}';
}
}
43 changes: 43 additions & 0 deletions materials/2024-2025/11a/MyDate/task.md
Original file line number Diff line number Diff line change
@@ -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
```

---

0 comments on commit 5faee98

Please sign in to comment.