Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Консольное приложение JAVA. Яндекс.Практикум#1

Open
V3hby wants to merge 6 commits intomain from
dev
Open

Консольное приложение JAVA. Яндекс.Практикум #1
V3hby wants to merge 6 commits intomain from
dev

Conversation

@V3hby
Copy link
Owner

@V3hby V3hby commented Mar 15, 2023

Написал первое консольное приложение в Java. Для сдачи ПР в Яндекс.Практикум

Copy link

@SeveNChaK SeveNChaK left a comment

Choose a reason for hiding this comment

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

В файлах код прыгает, отступы не одинаковые - рекомендую использовать встроенные форматтер. Если ты программируешь в IDE от JetBrains, то можешь пройтись по всем файлам и нажать комбинацию (Windows: Shift + Ctrl + Alt + L, MacOS: Shift + Option + Command + L), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).

double totalAmount = 0.0;
while (true) { // не стал делать проверку по введенному значению. Она есть дальше при делении счета.
System.out.println("Введите название и цену товара! Если хотите закончить, то введите 'завершить'!");
nameOfProduct = scanner.next();
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

⚠️ Лучше использовать nextLine, чтобы считать всю строку, потому что если ввести название из нескольких слов, то приложение упадет, так как после прочтения первого слова пойдет читать цену товара

System.out.println(String.format(fullListsCost, totalAmount) + calc.GetRubleAddition(priceOfProduct));
break;
} else {
priceOfProduct = scanner.nextDouble();
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

⚠️ Не хватает проверки на отрицательную цену. А также если ввести буквы, то приложение падает

while (true) {
while (!scanner.hasNextInt()) {
System.out.println("Не является числом, повторите ввод!");
String numberOfPersons1 = scanner.next();
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

Можно просто scanner.next(); без записи в переменную

System.out.println("Не является числом, повторите ввод!");
String numberOfPersons1 = scanner.next();
}
while (scanner.hasNextInt()) {
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

Этот цикл не нужен, мы уже сделали проверку в предыдущем цикле, так что тут точно будет int

numberOfPersons = scanner.nextInt();
if (numberOfPersons <= 1) {
System.out.println("Количество персон должно быть больше 1. Повторите ввод!");
} else if (numberOfPersons > 1) {
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

Можно просто } else {

@@ -0,0 +1,28 @@
public class Calculator {
public String GetRubleAddition(double num) {
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

Методы принято называть с маленькой буквы

System.out.println("Введите название и цену товара! Если хотите закончить, то введите 'завершить'!");
nameOfProduct = scanner.next();
Calculator calc = new Calculator();
{
Copy link

@SeveNChaK SeveNChaK Mar 15, 2023

Choose a reason for hiding this comment

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

Похоже на лишнюю скобочку. Ты получается просто весь код еще дополнительно в блок обернул, в этом нет необходимости. Кажется, что можно убрать ее и соответствующую ей закрывающую скобку

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@SeveNChaK SeveNChaK SeveNChaK left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /