forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Первый коммит проекта 2 спринта #1
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
TatiAnikina
wants to merge
2
commits into
main
Choose a base branch
from
dev
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
2 commits
Select commit
Hold shift + click to select a range
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 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| # Пустой репозиторий для работы с Java кодом в Android Studio | ||
| # Репозиторий Татьяны Аникиной |
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,65 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| ArrayList<Product> productsList = new ArrayList<>(); | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| public void input() { | ||
| System.out.println("После ввода всех товаров введите команду Завершить"); | ||
| String name; | ||
| double price; | ||
| System.out.println("Введите название товара"); | ||
| while (true) { | ||
| name = scanner.nextLine().trim(); | ||
| if (name.equalsIgnoreCase("Завершить")) { | ||
| productPrint(); | ||
| break; | ||
| } else { | ||
| System.out.println("Введите его стоимость через точку в формате рубли.копейки (00.00)"); | ||
| scanner.useLocale(Locale.ENGLISH); | ||
| while (true) { | ||
| if (scanner.hasNextDouble()) { | ||
| price = scanner.nextDouble(); | ||
| if (price >= 0) { | ||
| productsList.add(new Product(name, price)); | ||
| System.out.printf(String.format("Товар %s успешно добавлен, цена %.2f\n", name, price)); | ||
| System.out.println("Добавьте еще товар. Или введите команду Завершить"); | ||
| name = scanner.nextLine(); | ||
| break; | ||
| } else { | ||
| System.out.println("Вы ввели отрицательную стоимость. Введите в формате рубли.копейки (00.00)"); | ||
| name = scanner.nextLine(); // Очищаем неправильный ввод | ||
| } | ||
| } else { | ||
| System.out.println("Вы неверно ввели стоимость. Введите в формате рубли.копейки (00.00)"); | ||
| scanner.nextLine(); // Очищаем неправильный ввод | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void productPrint() { | ||
| System.out.println("Добавленные товары:"); | ||
| for (Product product : productsList) { | ||
| System.out.printf("%s %.2f \n", product.getName(), product.getPrice()); | ||
| } | ||
| } | ||
| public void finalCalculation(int people, Formatter formatter) { | ||
| System.out.printf("Общий счет: %.2f %s\n", totalSum(), formatter.formatter(totalSum())); | ||
| System.out.println("Выводим окончательный расчет"); | ||
| Double finalCalc = totalSum() / people; | ||
| System.out.printf(String.format("Для каждого из " + people + " человек сумма к оплате %.2f %s", finalCalc, formatter.formatter(finalCalc))); | ||
| } | ||
| public double totalSum() { | ||
| Double sum = 0.0; | ||
|
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. Можно здесь и примитивный тип использовать |
||
| for (Product product : productsList) { | ||
| sum += product.getPrice(); | ||
| } | ||
| return sum; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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,16 @@ | ||
| public class Formatter { | ||
| public String formatter(double sumForOne) { | ||
|
|
||
|
|
||
| if (sumForOne % 100 >= 11 && sumForOne % 100 <= 19) { | ||
| return "рублей"; | ||
| } else if (sumForOne % 10 == 1) { | ||
| return "рубль"; | ||
| } else if (sumForOne % 10 >= 2 && sumForOne % 10 <= 4) { | ||
| return "рубля"; | ||
| } else { | ||
| return "рублей"; | ||
| } | ||
|
|
||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,6 +1,40 @@ | ||
| import java.util.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| System.out.println("Добро пожаловать в калькулятор счета"); | ||
| Calculator calculator = new Calculator(); | ||
| Formatter formatter = new Formatter(); | ||
| int people = Counter.getQuantity(); | ||
| calculator.input(); | ||
| calculator.finalCalculation(people, formatter); | ||
| } | ||
| } | ||
|
|
||
| static class Counter { | ||
|
|
||
| public static int getQuantity() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| int quantity; | ||
|
|
||
| while (true) { | ||
| if (scanner.hasNextInt()) { | ||
| quantity = scanner.nextInt(); | ||
| if (quantity < 1) { | ||
| System.out.println("Введите корректное значение больше одного"); | ||
| } else if (quantity == 1) { | ||
| System.out.println("На одного человека нельзя разделить счет"); | ||
| } else { | ||
| System.out.println("Счет разделим на " + quantity + "-х человек"); | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Нужно ввести количество человек"); | ||
| scanner.next(); // Очищаем неправильный ввод | ||
| } | ||
| } | ||
| return quantity; | ||
| } | ||
| } | ||
| } |
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,15 @@ | ||
| public class Product { | ||
| private final String name; | ||
| private final double price; | ||
|
|
||
| public Product(String name, double price) { | ||
| this.name = name; | ||
| this.price = price; | ||
| } | ||
| public String getName() { | ||
| return name; | ||
| } | ||
| public double getPrice() { | ||
| return price; | ||
| } | ||
| } |
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.
Перед коммитом стоит приводить файлы к правильному стилю, так как код будут смотреть другие разработчики. В IDEA это легко делать путём вызова горячей комбинации клавиш (она зависит от ОС), её можно посмотреть в меню Code → Reformat Code