Skip to content

Homework #1#1

Open
vitalkava wants to merge 1 commit intomainfrom
dev
Open

Homework #1#1
vitalkava wants to merge 1 commit intomainfrom
dev

Conversation

@vitalkava
Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +4 to +5
private String carName;
private int carSpeed;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Поля лучше пометить final, тем самым исключив возможность их модификации

Comment on lines +13 to +19
public String getName() {
return carName;
}

public int getCarSpeed() {
return carSpeed;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно убрать две функции - геттеры, сделать переменные публичными и добавить к ним модификатор final - так часто делают с классами, у которых переменные инициализируются в конструкторе и никогда не меняются (дата классы)

Comment on lines +5 to +14
Auto winner = cars.get(0);
int theBiggestDistance = 0;
for (Auto car : cars) {
int distance = car.getCarSpeed() * 24;
if (distance > theBiggestDistance) {
theBiggestDistance = distance;
winner = car;
}
}
return winner;
Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants