-
Notifications
You must be signed in to change notification settings - Fork 2k
Дипломная работа первая часть #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ppetermsc
wants to merge
6
commits into
yandex-praktikum:main
Choose a base branch
from
ppetermsc:develop1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7224eca
Дипломная работа первая часть
ppetermsc e963df0
Обновление структуры: проект перемещен в папку Diplom_1
ppetermsc 4c1cf49
Create README.md
ppetermsc 5c69889
temp: save current state
ppetermsc 125f78c
merge: integrate updated test classes and gitignore
ppetermsc 91b7ae2
fix: remove build and IDE files from repository
ppetermsc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
11
Diplom/Diplom_1/src/main/java/praktikum/IngredientType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package praktikum; | ||
|
|
||
| /** | ||
| * Перечисление с типами ингредиентов. | ||
| * SAUCE – соус | ||
| * FILLING – начинка | ||
| */ | ||
| public enum IngredientType { | ||
| SAUCE, | ||
| FILLING | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛔️Нужно исправить. Тестируем только класс Burger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено, класс удален.