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
Binary file added .DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# System files
.DS_Store

# IDE
.idea/
*.iml
*.iws

# Build outputs
target/
build/
out/

# Logs
*.log
logs/

# Archives
*.zip
*.tar.gz

# Maven
pom.xml.versionsBackup
59 changes: 59 additions & 0 deletions Diplom/Diplom_1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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>

<groupId>org.example</groupId>
<artifactId>praktikum</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.13.2</junit.version>
<mockito.version>4.11.0</mockito.version>
<jacoco.version>0.8.8</jacoco.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
25 changes: 25 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/Bun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package praktikum;

/**
* Модель булочки для бургера.
* Булочке можно дать название и назначить цену.
*/
public class Bun {

public String name;
public float price;

public Bun(String name, float price) {
this.name = name;
this.price = price;
}

public String getName() {
return name;
}

public float getPrice() {
return price;
}

}
57 changes: 57 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/Burger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package praktikum;

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

/**
* Модель бургера.
* Бургер состоит из булочек и ингредиентов (начинка или соус).
* Ингредиенты можно перемещать и удалять.
* Можно распечать чек с информацией о бургере.
*/
public class Burger {

public Bun bun;
public List<Ingredient> ingredients = new ArrayList<>();

public void setBuns(Bun bun) {
this.bun = bun;
}

public void addIngredient(Ingredient ingredient) {
ingredients.add(ingredient);
}

public void removeIngredient(int index) {
ingredients.remove(index);
}

public void moveIngredient(int index, int newIndex) {
ingredients.add(newIndex, ingredients.remove(index));
}

public float getPrice() {
float price = bun.getPrice() * 2;

for (Ingredient ingredient : ingredients) {
price += ingredient.getPrice();
}

return price;
}

public String getReceipt() {
StringBuilder receipt = new StringBuilder(String.format("(==== %s ====)%n", bun.getName()));

for (Ingredient ingredient : ingredients) {
receipt.append(String.format("= %s %s =%n", ingredient.getType().toString().toLowerCase(),
ingredient.getName()));
}

receipt.append(String.format("(==== %s ====)%n", bun.getName()));
receipt.append(String.format("%nPrice: %f%n", getPrice()));

return receipt.toString();
}

}
36 changes: 36 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package praktikum;

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

/**
* Класс с методами по работе с базой данных.
*/
public class Database {

private final List<Bun> buns = new ArrayList<>();
private final List<Ingredient> ingredients = new ArrayList<>();

public Database() {
buns.add(new Bun("black bun", 100));
buns.add(new Bun("white bun", 200));
buns.add(new Bun("red bun", 300));

ingredients.add(new Ingredient(IngredientType.SAUCE, "hot sauce", 100));
ingredients.add(new Ingredient(IngredientType.SAUCE, "sour cream", 200));
ingredients.add(new Ingredient(IngredientType.SAUCE, "chili sauce", 300));

ingredients.add(new Ingredient(IngredientType.FILLING, "cutlet", 100));
ingredients.add(new Ingredient(IngredientType.FILLING, "dinosaur", 200));
ingredients.add(new Ingredient(IngredientType.FILLING, "sausage", 300));
}

public List<Bun> availableBuns() {
return buns;
}

public List<Ingredient> availableIngredients() {
return ingredients;
}

}
32 changes: 32 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/Ingredient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package praktikum;

/**
* Модель ингредиента.
* Ингредиент: начинка или соус.
* У ингредиента есть тип (начинка или соус), название и цена.
*/
public class Ingredient {

public IngredientType type;
public String name;
public float price;

public Ingredient(IngredientType type, String name, float price) {
this.type = type;
this.name = name;
this.price = price;
}

public float getPrice() {
return price;
}

public String getName() {
return name;
}

public IngredientType getType() {
return type;
}

}
11 changes: 11 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/IngredientType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package praktikum;

/**
* Перечисление с типами ингредиентов.
* SAUCE – соус
* FILLING – начинка
*/
public enum IngredientType {
SAUCE,
FILLING
}
38 changes: 38 additions & 0 deletions Diplom/Diplom_1/src/main/java/praktikum/Praktikum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package praktikum;

import java.util.List;

public class Praktikum {

public static void main(String[] args) {
// Инициализируем базу данных
Database database = new Database();

// Создадим новый бургер
Burger burger = new Burger();

// Считаем список доступных булок из базы данных
List<Bun> buns = database.availableBuns();

// Считаем список доступных ингредиентов из базы данных
List<Ingredient> ingredients = database.availableIngredients();

// Соберём бургер
burger.setBuns(buns.get(0));

burger.addIngredient(ingredients.get(1));
burger.addIngredient(ingredients.get(4));
burger.addIngredient(ingredients.get(3));
burger.addIngredient(ingredients.get(5));

// Переместим слой с ингредиентом
burger.moveIngredient(2, 1);

// Удалим ингредиент
burger.removeIngredient(3);

// Распечатаем рецепт бургера
System.out.println(burger.getReceipt());
}

}
42 changes: 42 additions & 0 deletions Diplom/Diplom_1/src/test/java/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import praktikum.Bun;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class BunTest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Тестируем только класс Burger

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено, класс удален.

private final String name;
private final float price;

public BunTest(String name, float price) {
this.name = name;
this.price = price;
}

@Parameterized.Parameters(name = "Тест {index}: булочка ''{0}'' с ценой {1}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"черная булочка", 100f},
{"белая булочка", 200f},
{"красная булочка", 300f}
});
}

@Test
public void testGetName() {
Bun bun = new Bun(name, price);
assertEquals("Название булочки должно совпадать", name, bun.getName());
}

@Test
public void testGetPrice() {
Bun bun = new Bun(name, price);
assertEquals("Цена булочки должна совпадать", price, bun.getPrice(), 0.001);
}
}
Loading