Skip to content

console application #1 - #1

Open
Liocha wants to merge 2 commits into
mainfrom
dev
Open

Liocha wants to merge 2 commits into
mainfrom
dev

Conversation

@Liocha

@Liocha Liocha commented Oct 10, 2023

Copy link
Copy Markdown
Owner

Проектная работа №1
Пишем консольное приложение №1

Comment thread src/main/java/Main.java
Comment on lines +5 to +10
int peopleCount;
String productName;
double productPrice;
Product product;
double result;
String answer;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Переменные нужно объявлять как можно ближе к месту их использования

Comment thread src/main/java/Main.java Outdated
Comment on lines +69 to +70
double total = 0;
String products = "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Эти поля можно приватными сделать, раз у тебя есть к ним get методы

Comment thread src/main/java/Main.java Outdated
Comment on lines +78 to +80
void calculateTotal(double productPrice) {
this.total = this.total + productPrice;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это можно не выносить в отдельную функцию

Comment thread src/main/java/Main.java Outdated
Comment on lines +92 to +93
String name;
double price;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

поля можно сделать неизменяемыми:

Suggested change
String name;
double price;
final String name;
final double price;

Comment thread src/main/java/Main.java Outdated
} while (!answer.equalsIgnoreCase("завершить"));
System.out.println("Добавленные товары:" + calculator.getProducts());
result = calculator.getTotal() / peopleCount;
System.out.println("Каждый человк должен заплатить: " + Formatter.getFormatPrice(result) + Formatter.getEnding(result));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Опечатка

Suggested change
System.out.println("Каждый человк должен заплатить: " + Formatter.getFormatPrice(result) + Formatter.getEnding(result));
System.out.println("Каждый человек должен заплатить: " + Formatter.getFormatPrice(result) + Formatter.getEnding(result));

Comment thread src/main/java/Main.java Outdated
Comment on lines +108 to +114
if (result == 1) {
return " рубль";
} else if (result > 2 && result < 5) {
return " рубля";
} else {
return " рублей";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Чтобы функция была более универсальной, можно не добавлять к возвращаемой строке пробел, а делать это в точке вызова функции:

Suggested change
if (result == 1) {
return " рубль";
} else if (result > 2 && result < 5) {
return " рубля";
} else {
return " рублей";
}
if (result == 1) {
return "рубль";
} else if (result > 2 && result < 5) {
return "рубля";
} else {
return "рублей";
}

@Liocha

Liocha commented Oct 11, 2023

Copy link
Copy Markdown
Owner Author

Поправил ошибки во втором коммите

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants