Repository navigation
SECOND PR #40
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
Closed
Closed
SECOND PR #40
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6fb7da
Add dev branch
ce8e2df
test
vvverman 057ff97
test
vvverman 167bc60
Merge remote-tracking branch 'origin/dev' into dev
vvverman 75f8615
test
vvverman 8dc42dc
test
vvverman ffa6319
Новая версия самой лучшей программы в мире
vvverman 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
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
| package vvverman.lesson1; | ||
|
|
||
| import vvverman.lesson1.entity.Product; | ||
| import vvverman.lesson1.services.CalculatorService; | ||
| import vvverman.lesson1.services.FormatorService; | ||
| import vvverman.lesson1.services.ProductService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| public class App { | ||
|
|
||
| public static void main(final String[] args) { | ||
| List<Product> products = ProductService.getProducts(); | ||
| double invoice = ProductService.getSumProducts(products); | ||
| double sumForPersons = CalculatorService.getSumForPersons(invoice); | ||
| System.out.println(FormatorService.getRubleAddition(sumForPersons)); | ||
|
|
||
|
|
||
| } | ||
| } |
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,45 @@ | ||
| package vvverman.lesson1.entity; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Product { | ||
| String name; | ||
| double price; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Product{" + | ||
| "name='" + name + '\'' + | ||
| ", price=" + price + | ||
| '}'; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Product product = (Product) o; | ||
| return Double.compare(product.price, price) == 0 && name.equals(product.name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, price); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public double getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| public void setPrice(double price) { | ||
| this.price = price; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/main/java/vvverman/lesson1/services/CalculatorService.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,45 @@ | ||
| package vvverman.lesson1.services; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class CalculatorService { | ||
| public static double getSumForPersons(double sum) { | ||
|
|
||
| double total = 0; | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько персон разделить счёт, Господа?"); | ||
| while (scanner.hasNextInt()) { | ||
| int numberOfPersons = scanner.nextInt(); | ||
| if (numberOfPersons == 1) { | ||
| System.out.println("Ошибка, на одного делить нет смысла"); | ||
| } else if (numberOfPersons < 1) { | ||
| System.out.println("Ошибка, на 0, вообще, делить незя, и антиматерия в нашей задаче не участвует"); | ||
| } else { | ||
| total = sum / numberOfPersons; | ||
| break; | ||
| } | ||
| System.out.println("Попробуй ещё раз"); | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| // public static int countPersons(int number) { | ||
| // | ||
| // while (scanner.hasNextInt()) { | ||
| // | ||
| // | ||
| // if (number == 1) { | ||
| // System.out.println("Ошибка, на одного делить нет смысла"); | ||
| // } else if (number < 1) { | ||
| // System.out.println("Ошибка, на 0, вообще, делить незя, и антиматерия в нашей задаче не участвует"); | ||
| // } else if (number > 1) { | ||
| // total = count / number; | ||
| // | ||
| // double value = total; | ||
| // String result = String.format("%.2f", value); | ||
| // | ||
| // } | ||
| // } | ||
23 changes: 23 additions & 0 deletions
23
src/main/java/vvverman/lesson1/services/FormatorService.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,23 @@ | ||
| package vvverman.lesson1.services; | ||
|
|
||
| public class FormatorService { | ||
|
|
||
| public static String getRubleAddition(double formattedResult) { | ||
|
|
||
|
|
||
| int lastCharacter = (int) (Math.floor(formattedResult) % 10); | ||
| String result = String.format("%.2f", formattedResult); | ||
| switch (lastCharacter) { | ||
|
|
||
| case 1: | ||
| return result + " рубль"; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| return result + " рубля"; | ||
| default: | ||
| return result + " рублей"; | ||
|
|
||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/main/java/vvverman/lesson1/services/ProductService.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,49 @@ | ||
| package vvverman.lesson1.services; | ||
|
|
||
| import vvverman.lesson1.entity.Product; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Scanner; | ||
|
|
||
| public class ProductService { | ||
|
|
||
| public static List<Product> getProducts() { | ||
| ArrayList<Product> products = new ArrayList<>(); | ||
| boolean whileCondition = false; | ||
| while (!whileCondition) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| Product product = new Product(); | ||
| System.out.println("Введите имя товара"); | ||
| product.setName(scanner.nextLine()); | ||
|
|
||
| System.out.println("Введите цену товара"); | ||
| product.setPrice(scanner.nextDouble()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Точно также как с |
||
|
|
||
| products.add(product); | ||
| System.out.println("Напишите \"завершить\", чтобы завершить"); | ||
|
|
||
| String command = scanner.next(); | ||
| whileCondition = command.equalsIgnoreCase("завершить"); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| System.out.println("Добавленные товары:\n "); | ||
| for (Product product : products) { | ||
| System.out.println(product.toString()); | ||
|
|
||
| } | ||
| System.out.println("Общая сумма товаров: " + getSumProducts(products)); | ||
| return products; | ||
| } | ||
|
|
||
| public static double getSumProducts(List<Product> products) { | ||
| double count = 0.0; | ||
| for (Product product : products) { | ||
| count = count + product.getPrice(); | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
| } | ||
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.
Закомментированный код лучше убрать.