Skip to content

Проектная работа №1. Версия 2. #68

Open
artemyarovikov wants to merge 5 commits into
Yandex-Practicum:masterfrom
artemyarovikov:master
Open

Проектная работа №1. Версия 2. #68
artemyarovikov wants to merge 5 commits into
Yandex-Practicum:masterfrom
artemyarovikov:master

Conversation

@artemyarovikov

Copy link
Copy Markdown

Переписал код склонения рубля, сейчас работает с любыми суммами.

Comment thread src/main/java/Main.java

public static void rublesName(double cost) {
if (cost % 10 == 1 && cost != 11 && cost % 100 != 11) {
System.out.println(" рубль.");

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
public static void rublesName(double cost) {
if (cost % 10 == 1 && cost != 11 && cost % 100 != 11) {
System.out.println(" рубль.");
} else if (cost % 10 >= 2 && cost % 10 <= 4) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cost % 10 повторяется несколько раз, можно посчитать 1 раз, записать в переменную и использовать её.
Ещё в эту ветку попадают числа 12, 13 и 14, а должно быть для них "рублей"

Comment thread src/main/java/Main.java
}

public static void rublesName(double cost) {
if (cost % 10 == 1 && cost != 11 && cost % 100 != 11) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cost != 11 и cost % 100 != 11 это одно и тоже, при делении по модулю числа 11 на 100 будет всё равно 11

@artemyarovikov artemyarovikov Oct 6, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Это для чисел больше 100

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно оставить только cost % 100 != 11. Для числа 111 cost % 100 = 11, и для числа 11 cost % 100 = 11

Comment thread src/main/java/People.java
int passPeople = scannerPeople.nextInt();
if (passPeople > 1) {
countPeople = passPeople;
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.

Можно число людей сделать возвращаемым значением метода howPeople, и избавиться от переменной countPeople

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