forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Учтены замечания после ревью1 #6
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
goldanna0
wants to merge
8
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
8 commits
Select commit
Hold shift + click to select a range
b8ef023
правки по результатам ревью1
goldanna0 bd3f044
правки по результатам ревью1
goldanna0 5d0822f
правки по результатам ревью1_
goldanna0 d6bb02b
Merge branch 'main' into dev
goldanna0 4d19814
Add files via upload
goldanna0 3171265
по результатам ревью1
goldanna0 7bb2bcb
удален закомментированный код
goldanna0 c59fb35
Item::inputData
goldanna0 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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| double totalPrice; | ||
| private StringBuilder itemList = new StringBuilder(); | ||
| private int countOfItems; | ||
| private int peopleCount; | ||
|
|
||
| public Calculator(int count) { | ||
| peopleCount = count; | ||
| } | ||
|
|
||
| // метод добавляет один новый товар в расчет калькулятора | ||
| private void addNewItem() { | ||
| Item newitem = new Item(); | ||
| newitem.inputData(); | ||
| itemList.append("\n").append(newitem.name); | ||
| totalPrice += newitem.price; | ||
| countOfItems++; | ||
| System.out.println("Товар " + newitem.name + " добавлен в перечень"); | ||
| //System.out.println("В калькуляторе "+countOfItems + " товаров"); | ||
|
|
||
| } | ||
|
|
||
| // метод определяет, нужно ли продолжать добавленее товаров в калькулятор | ||
| private boolean needToStop() { | ||
| System.out.println("Хотите добавить еще один товар или завершить?"); | ||
| Scanner newScanner = new Scanner(System.in); | ||
| String answer = newScanner.next(); | ||
| // для всех ответов кроме "завершить" в любом регистре вернет false, то есть ввод товаров завершен | ||
| return answer.equalsIgnoreCase("Завершить"); | ||
|
|
||
| } | ||
|
|
||
| public void addAllItems() { | ||
| System.out.println("Заполняем перечень товаров"); | ||
| while (true) { | ||
| addNewItem(); | ||
| if (needToStop()) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // этот метод выводит всю информацию, использовавшуюся для расчета, и результаты расчета калькулятора | ||
| public void printResults() { | ||
| double pricePerPerson; | ||
| String strRub; | ||
| String template = "С каждого человека: %.2f "; | ||
| System.out.println("Общая сумма товаров в расчете:" + totalPrice); | ||
| System.out.println("Добавленные товары:" + itemList); | ||
| pricePerPerson = totalPrice / peopleCount; | ||
| strRub = formatRubString((int) Math.floor(pricePerPerson)); | ||
| template += strRub; | ||
| System.out.println(String.format(template, pricePerPerson)); | ||
| } | ||
|
|
||
| // форматирование "рубль" в нужный падеж для вывода результата | ||
| // 1 рубль 2-4 рубля, 5-20 рублей, для чисел от 20 до 100 формат повторяет правило для остатка от деления данного числа на 10 | ||
| private String formatRubString(int price) { | ||
| String priceStr; | ||
| if (price > 100) price %= 100; | ||
| if (price > 20) price %= 10; | ||
| if (price == 1) { // 1 рубль | ||
| priceStr = "рубль"; | ||
| } else if ((price > 1) && (price < 5)) { // 2,3,4 рубля | ||
| priceStr = "рубля"; | ||
| } else { // 5-20 рублей | ||
| priceStr = "рублей"; | ||
| } | ||
| return priceStr; | ||
|
|
||
| } | ||
|
|
||
| } | ||
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 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Item { | ||
|
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. Это тоже лишний, похоже, что старая версия файла |
||
| String name; | ||
| double price; | ||
|
|
||
| public void inputData() { //Информацию о новом товаре вводит пользователь | ||
|
|
||
| Scanner newScanner = new Scanner(System.in); | ||
| System.out.println("Укажите название товара:"); | ||
| name = newScanner.next(); | ||
|
|
||
| while (true) { //повторяем, пока пользователь не введет данные в нужном формате | ||
| System.out.println("Укажите цену товара:"); | ||
| if (newScanner.hasNextDouble()) { //проверка типа (ожидаем double) | ||
| price = newScanner.nextDouble(); | ||
| break; | ||
| } else { //проверка формата введенных пользователем данных завершилась неуспешно | ||
| System.out.println("Неверный формат ввода"); | ||
| newScanner.next(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
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,75 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| double totalPrice; | ||
| private StringBuilder itemList = new StringBuilder(); | ||
| private int countOfItems; | ||
| private int peopleCount; | ||
|
|
||
| public Calculator(int count) { | ||
| peopleCount = count; | ||
| } | ||
|
|
||
| // метод добавляет один новый товар в расчет калькулятора | ||
| private void addNewItem() { | ||
| Item newitem = new Item(); | ||
| newitem.inputData(); | ||
| itemList.append("\n").append(newitem.name); | ||
| totalPrice += newitem.price; | ||
| countOfItems++; | ||
| System.out.println("Товар " + newitem.name + " добавлен в перечень"); | ||
|
|
||
| } | ||
|
|
||
| // метод определяет, нужно ли продолжать добавленее товаров в калькулятор | ||
| private boolean needToStop() { | ||
| System.out.println("Хотите добавить еще один товар или завершить?"); | ||
| Scanner newScanner = new Scanner(System.in); | ||
| String answer = newScanner.next(); | ||
| // для всех ответов кроме "завершить" в любом регистре вернет false, то есть ввод товаров завершен | ||
| return answer.equalsIgnoreCase("Завершить"); | ||
|
|
||
| } | ||
|
|
||
| public void addAllItems() { | ||
| System.out.println("Заполняем перечень товаров"); | ||
| while (true) { | ||
| addNewItem(); | ||
| if (needToStop()) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // этот метод выводит всю информацию, использовавшуюся для расчета, и результаты расчета калькулятора | ||
| public void printResults() { | ||
| double pricePerPerson; | ||
| String strRub; | ||
| String template = "С каждого человека: %.2f "; | ||
| System.out.println("Общая сумма товаров в расчете:" + totalPrice); | ||
| System.out.println("Добавленные товары:" + itemList); | ||
| pricePerPerson = totalPrice / peopleCount; | ||
| strRub = formatRubString((int) Math.floor(pricePerPerson)); | ||
| template += strRub; | ||
| System.out.println(String.format(template, pricePerPerson)); | ||
| } | ||
|
|
||
| // форматирование "рубль" в нужный падеж для вывода результата | ||
| // 1 рубль 2-4 рубля, 5-20 рублей, для чисел от 20 до 100 формат повторяет правило для остатка от деления данного числа на 10 | ||
| private String formatRubString(int price) { | ||
| String priceStr; | ||
| if (price > 100) price %= 100; | ||
| if (price > 20) price %= 10; | ||
| if (price == 1) { // 1 рубль | ||
| priceStr = "рубль"; | ||
| } else if ((price > 1) && (price < 5)) { // 2,3,4 рубля | ||
| priceStr = "рубля"; | ||
| } else { // 5-20 рублей | ||
| priceStr = "рублей"; | ||
| } | ||
| return priceStr; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
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,27 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Item { | ||
| String name; | ||
| double price; | ||
|
|
||
| public void inputData() { //Информацию о новом товаре вводит пользователь | ||
|
|
||
| Scanner newScanner = new Scanner(System.in); | ||
| System.out.println("Укажите название товара:"); | ||
| name = newScanner.next(); | ||
|
|
||
| while (true) { //повторяем, пока пользователь не введет данные в нужном формате | ||
| System.out.println("Укажите цену товара:"); | ||
| if (newScanner.hasNextDouble()) { //проверка типа (ожидаем double) | ||
| price = newScanner.nextDouble(); | ||
| if (price <= 0) { | ||
| System.out.println("Цена товара должна быть строго больше 0!"); | ||
| } else break; | ||
| } else { //проверка формата введенных пользователем данных завершилась неуспешно | ||
| System.out.println("Неверный формат ввода"); | ||
| newScanner.next(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
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,8 +1,41 @@ | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| // dev branch for Y.Practicum | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
| int count = getPeopleCount(); //определили число гостей | ||
| Calculator myCalc = new Calculator(count); //создали калькулятор | ||
| myCalc.addAllItems(); //получили информацию о товарах и их ценах для расчета | ||
| myCalc.printResults(); //вывели результаты расчета | ||
|
|
||
| } | ||
|
|
||
| // этот метод возвращает введенное пользователем число гостей, на которых нужно делить счет | ||
| private static int getPeopleCount() { | ||
| int peopleCount; | ||
| Scanner myScanner = new Scanner(System.in); | ||
| System.out.println("Укажите, на какое количество людей нужно будет поделить счет? (целое число>1)"); | ||
| while (true) { //повторяем, пока пользователь не введет корректное число гостей | ||
| if (myScanner.hasNextInt()) { //проверка типа (ожидаем целое число) | ||
| peopleCount = myScanner.nextInt(); | ||
| if (peopleCount > 1) { //если получили корректное число гостей, то пора переходить к калькулятору | ||
| break; | ||
| } else if (peopleCount == 1) { | ||
| System.out.println("Нет смысла делить расходы на одного"); | ||
| } else { // введено <=0 в качестве числа гостей | ||
| System.out.println("Введено некорректное число для подсчета"); | ||
| } | ||
| } else { //проверка формата введенных пользователем данных завершилась неуспешно ( не является int) | ||
| System.out.println("Неверный формат ввода"); // /дробное или вообще не число | ||
| myScanner.next(); | ||
| } | ||
| System.out.println("Укажите корректное количество гостей"); | ||
| } | ||
| return peopleCount; | ||
| } | ||
|
|
||
| } | ||
|
|
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.
Это похоже на лишний файл, можно удалить